import java.applet.Applet; import java.awt.*; // This appears in Core Web Programming from // Prentice Hall Publishers, and may be freely used // or adapted. 1997 Marty Hall, hall@apl.jhu.edu. /** A better whiteboard that lets you enter * text in addition to freehand drawing. */ public class Whiteboard extends SimpleWhiteboard { private FontMetrics fm; public void init() { super.init(); Font font = new Font("Helvetica", Font.BOLD, 20); setFont(font); fm = getFontMetrics(font); } public boolean keyDown(Event e, int key) { String s = String.valueOf((char)key); getGraphics().drawString(s, lastX, lastY); return(record(lastX + fm.stringWidth(s), lastY)); } }