import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/** A better whiteboard that lets you enter
* text in addition to freehand drawing.
*
******************
public class Whiteboard extends SimpleWhiteboard {
protected FontMetrics fm;
public void init() {
super.init();
Font font = new Font("Serif", Font.BOLD, 20);
setFont(font);
fm = getFontMetrics(font);
addKeyListener(new CharDrawer());
}
private class CharDrawer extends KeyAdapter {
// When user types a printable character,
// draw it and shift position rightwards.
public void keyTyped(KeyEvent event) {
String s = String.valueOf(event.getKeyChar());
getGraphics().drawString(s, lastX, lastY);
record(lastX + fm.stringWidth(s), lastY);
}
}
}