import java.applet.*; import java.awt.*; public class second extends Applet { private int lastx, lasty; Button clear_button; Graphics g; public void init() { clear_button = new Button("Clear"); this.add(clear_button); g = this.getGraphics(); } public boolean mouseDown(Event e, int x, int y) { lastx = x; lasty = y; return true; } public boolean mouseDrag(Event e, int x, int y) { g.setColor(Color.black) ; g.drawLine(lastx, lasty, x, y); lastx = x; lasty = y; return true; } public boolean keyDown(Event e, int key) { if ((e.id == Event.KEY_PRESS) && (key == 'c' ) ) { clear() ; return true; } else return false; } public boolean action(Event e, Object arg) { if (e.target == clear_button) { clear(); return true; } else return false; } public void clear() { g.setColor(this.getBackground()); g.fillRect(0, 0, bounds().width, bounds().height); } }