import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

/** The listener used by CircleDrawer1. Note call
 *  to getSource to obtain reference to the applet.
 *  <P>
 *  Taken from Core Web Programming Java 2 Edition
 *  from Prentice Hall and Sun Microsystems Press,
 *  http://www.corewebprogramming.com/.
 *  May be freely used or adapted.
 */

public class CircleListener extends MouseAdapter {
  private int radius = 25;

  public void mousePressed(MouseEvent event) {
    // Note that we have to find the object which is the source of events,
    // because we want to draw circles on the applet that generates events

    Applet app = (Applet)event.getSource();   // find the source

    Graphics g = app.getGraphics();    // find the graphics context

    g.fillOval(event.getX()-radius,    // draw a circle on the applet 
               event.getY()-radius,
               2*radius,
               2*radius);
  }
}