//******************************************************************** // Dots.java Author: Lewis and Loftus // DotsAppletModified.java modified: Omar // // Instead of creating a separate listener object, I allow the applet // itself to serve as listener. I just need one single class that extends // Applet class and implements MouseListener interface. // Note that a reference to the Applet, using the this reference, is passed // to addMouseListener method. So not only does the Applet generate the mouse // events, it also listens for them to occur and responds. //******************************************************************** import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class DotsAppletModified extends Applet implements MouseListener { private final int APPLET_WIDTH = 200; private final int APPLET_HEIGHT = 100; private final int RADIUS = 6; private Point clickPoint = null; public void setPoint (Point point) { clickPoint = point; } public void init() { addMouseListener (this); setBackground (Color.black); setSize (APPLET_WIDTH, APPLET_HEIGHT); } public void paint (Graphics page) { page.setColor (Color.green); if (clickPoint != null) page.fillOval (clickPoint.x - RADIUS, clickPoint.y - RADIUS, RADIUS * 2, RADIUS * 2); } public void mouseClicked (MouseEvent event) { clickPoint = event.getPoint(); repaint(); } public void mousePressed (MouseEvent event) {} public void mouseReleased (MouseEvent event) {} public void mouseEntered (MouseEvent event) {} public void mouseExited (MouseEvent event) {} }