//******************************************************************** // Dots.java Author: Lewis and Loftus // // Demonstrates events and listeners. //******************************************************************** import java.applet.Applet; import java.awt.*; // import java.awt.event.*; public class Dots extends Applet { private final int APPLET_WIDTH = 200; private final int APPLET_HEIGHT = 100; private final int RADIUS = 6; private Point clickPoint = null; //----------------------------------------------------------------- // Creates a listener for mouse events for this applet. //----------------------------------------------------------------- public void init() { DotsMouseListener listener = new DotsMouseListener(this); addMouseListener(listener); setBackground (Color.black); setSize (APPLET_WIDTH, APPLET_HEIGHT); } //----------------------------------------------------------------- // Draws the dot at the appropriate location. //----------------------------------------------------------------- public void paint (Graphics page) { page.setColor (Color.green); if (clickPoint != null) page.fillOval (clickPoint.x - RADIUS, clickPoint.y - RADIUS, RADIUS * 2, RADIUS * 2); } //----------------------------------------------------------------- // Sets the point at which to draw the next dot. //----------------------------------------------------------------- public void setPoint (Point point) { clickPoint = point; } }