import java.applet.*; import java.awt.*; public class StandaloneScribble extends Scribble { public static void main(String args[]) { Applet applet = new StandaloneScribble(); Frame frame = new AppletFrame("Scribble", applet, 300, 300); } } class AppletFrame extends Frame { public AppletFrame(String title, Applet applet, int width, int height) { super(title); MenuBar menubar = new MenuBar(); Menu file = new Menu("File", true); menubar.add(file); file.add("Quit"); this.setMenuBar(menubar); this.add("Center", applet); this.resize(width, height); this.show(); applet.init(); applet.start(); } public boolean action(Event e, Object arg) { if (e.target instanceof MenuItem) { String label = (String) arg; if (label.equals("Quit")) System.exit(0); } return false; } } class Scribble extends Applet { private int lastX = 0; private int lastY = 0; public boolean mouseDown(Event e, int x, int y) { lastX = x; lastY = y; return true; } public boolean mouseDrag(Event e, int x, int y) { Graphics g = getGraphics(); g.drawLine(lastX, lastY, x, y); lastX = x; lastY = y; return true; } }