
/****************************************************************
/*  DoodleIC2.java      Authors: Lewis and Loftus
/*                      Updated: Bary W Pollack
/*
/*  Demonstrates the use of GUI components.
/*  Demonstrates use of inner classes.
/*  Demonstrates using Canvas within a Panel and Layout Managers
/***************************************************************/

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class DoodleIC2 extends Applet {

    //------------------------------------------------------------
    //  Creates the GUI components and adds them to the applet.
    //  The applet serves as the listener for the button.
    //    Use Panels to control the layout of the components on
    //  the applet canvas.
    //------------------------------------------------------------
    public void init() {
        setLayout(new BorderLayout());
        Panel panelTop   = new Panel(new FlowLayout(FlowLayout.CENTER));
        Label titleLabel = new Label("Doodle using the mouse.");
        titleLabel.setBackground(Color.green);
        panelTop.add(titleLabel);
        add(panelTop, BorderLayout.NORTH);

        Panel panelCanvas = new Panel(new FlowLayout(FlowLayout.CENTER));
        canvas = new DoodleCanvasIC2();
        panelCanvas.add(canvas);
        add(panelCanvas, BorderLayout.CENTER);

        Panel panelClear = new Panel(new FlowLayout(FlowLayout.CENTER, 10, 95));
        Button clearButton = new Button(" Clear ");
        clearButton.setBackground(Color.cyan);
        clearButton.addActionListener(new ClearHandler());
        panelClear.add(clearButton);
        add(panelClear, BorderLayout.EAST);

        Panel panelBottom = new Panel(new FlowLayout(FlowLayout.CENTER));
        Label bottomLabel = new Label("Now, what happens if you "
                                      + "resize the applet?");
        bottomLabel.setBackground(Color.green);
        panelBottom.add(bottomLabel);
        add(panelBottom, BorderLayout.SOUTH);

        setBackground(Color.green);
        setSize(APPLET_WIDTH, APPLET_HEIGHT);
    }

    //------------------------------------------------------------
    //  Clears the canvas when the clear button is pushed.
    //------------------------------------------------------------
    class ClearHandler implements ActionListener {
        public void actionPerformed(ActionEvent event) {
            canvas.clear();
        }
    }

    private final int APPLET_WIDTH  = 300;
    private final int APPLET_HEIGHT = 275;
    private DoodleCanvasIC2 canvas;
}
