//********************************************************************
//  Dots.java       Authors: Lewis and Loftus
//                  Updated: Bary W Pollack
//
//  Demonstrates events and listeners.
//  Demonstrates setting up and using a "callback" handle
//********************************************************************

import java.applet.Applet;
import java.awt.*;

public class Dots extends Applet {

    private final int APPLET_WIDTH  = 250;
    private final int APPLET_HEIGHT = 100;
    private final int RADIUS = 6;
    private Point clickPoint = null;

    //-----------------------------------------------------------------
    //  Creates a listener for mouse events for this applet
    //  The DotsMouseListener accepts a "callback" handle for its
    //  later use
    //-----------------------------------------------------------------
    public void init() {
        DotsMouseListener listener = new DotsMouseListener(this);
        addMouseListener(listener);

        setBackground(Color.black);
        setSize(APPLET_WIDTH, APPLET_HEIGHT);
    } // end init()

    //-----------------------------------------------------------------
    //  Draws the dot at the appropriate location
    //-----------------------------------------------------------------
    public void paint(Graphics g) {
        g.setColor(Color.green);
        if (clickPoint != null)
            g.fillOval(clickPoint.x - RADIUS, clickPoint.y - RADIUS,
                       RADIUS * 2, RADIUS * 2);
        showStatus(" Click the mouse in the applet...");
    } // end paint()

    //-----------------------------------------------------------------
    //  Sets the point at which to draw the next dot
    //-----------------------------------------------------------------
    public void setPoint(Point point) {
        clickPoint = point;
    } // end setPoint()

} // end class Dots
