// Spots.java
// Demos mousePressed events
// APPLET CODE="Spots" HEIGHT=250 WIDTH=250
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Spots extends JApplet {
	final int MAXSPOTS = 10;
	int xSpot;
	int ySpot;
	int currSpot = 0;

	public void init( ) {
		xSpot = -10;
		ySpot = -10;
		setBackground( Color.white );

		// add anonymous inner class to applet to listen for mousePressed event
		addMouseListener( 
			new MouseAdapter( ) {
				public void mousePressed( MouseEvent e ) {
					if ( currSpot < MAXSPOTS ) {
						showStatus( "Mouse down at " + e.getX( ) + ", " + e.getY( ) );
						xSpot = e.getX( );
						ySpot = e.getY( );
						currSpot++;
						repaint( );
					}
					else {
						showStatus( "Too many spots." );
					}
				}
			}
		);
	}

	public void paint( Graphics g ) {
		g.setColor( Color.blue );
		g.fillOval( xSpot - 10, ySpot - 10, 20, 20 );
	}
}