import java.applet.*; import java.awt.*; // used: setenv CLASSPATH .:/n/state/0/parent/WWW/java public class ClearableScribble extends ColorScribble { private Button clear_button; public void init() { super.init(); // Create a button and addit to the applet clear_button = new Button("Clear"); clear_button.setForeground(Color.black); clear_button.setBackground(Color.lightGray); this.add(clear_button); } public boolean action(Event event, Object arg) { // If our button was clicked on, handle it. // Otherwise, let our superclass handle it if it wants to. if (event.target == clear_button) { Graphics g = this.getGraphics(); Rectangle r = this.bounds(); g.setColor(this.getBackground()); g.fillRect(r.x,r.y,r.width,r.height); g.setColor(this.getForeground()); return true; } else return super.action(event,arg); } }