//******************************************************************** // Doodle.java Author: Lewis and Loftus // // Demonstrates the use of GUI components. //******************************************************************** import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class Doodle extends Applet implements ActionListener { private int APPLET_WIDTH = 300; private int APPLET_HEIGHT = 250; private Label titleLabel; private DoodleCanvas canvas; private Button clearButton; //----------------------------------------------------------------- // Creates the GUI components and adds them to the applet. The // applet serves as the listener for the button. //----------------------------------------------------------------- public void init () { titleLabel = new Label ("Doodle using the mouse."); titleLabel.setBackground (Color.cyan); add (titleLabel); canvas = new DoodleCanvas(); add (canvas); clearButton = new Button("Clear"); clearButton.addActionListener (this); add (clearButton); setBackground (Color.cyan); setSize (APPLET_WIDTH, APPLET_HEIGHT); } //----------------------------------------------------------------- // Clears the canvas when the clear button is pushed. //----------------------------------------------------------------- public void actionPerformed (ActionEvent event) { canvas.clear(); } }