import java.awt.*;
import java.awt.event.*;

        // In this version (compare AWTMouseDrawing2.java) the mouse
        // listener methods are implemented directly by the
        // DrawingCanvas class, which is a subclass of Canvas.
public class MouseDrawing1 extends Frame implements ActionListener {
    public MouseDrawing1(){
        final int width = 400, height = 400;
        setSize(width,height);
        setBackground(Color.white);

        Panel panel = new Panel();
        // Add the buttons ...
        panel.add(newButton(clearString));
        panel.add(newButton(quitString));
        add(panel,"South");
        // ... and the drawing area.
        add(getCanvas(),"Center");
    }

        // Work out which button was pressed.
    public void actionPerformed(ActionEvent e){
        String command = e.getActionCommand();

        if(command.equals(clearString)){
            // Clear the canvas.
            getCanvas().clear();
        }
        else if(command.equals(quitString)){
            System.exit(0);
        }
        else{
            System.err.println("Unknown command: "+e);
        }
    }

    // Create a new button with label and command.
    // Use the label as the associated command.
    protected Button newButton(String label){
        Button b = new Button(label);
        b.addActionListener(this);
        b.setActionCommand(label);
        return b;
    }

    protected DrawingCanvas getCanvas(){
        return canvas;
    }

    // Where to draw.
    private DrawingCanvas canvas = new DrawingCanvas();
    // The labels for the buttons.
    private static final String clearString = "Clear";
    private static final String quitString = "Quit";
}
