/**
* This program draws a circle at each place where
* you click the mouse. It is an example of an
* applet.
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class DrawFigure extends Applet
    implements MouseListener{
	private String msg;
	private int[] x = new int[50];
	private int[] y = new int[50];
	private int n = 0;

	public DrawFigure (){
		/* This statement says that mouse events         */
		/* occurring in this class should be sent to the */
		/* MouseListener in this class.                  */
		this.addMouseListener(this);
	}

	public void init(){
		msg = "Starting";
	}

	public void paint(Graphics g){
		//This will draw a circle wherever you clicked
		for (int i = 0; i < n; i++)
		{
			g.drawOval(x[i]-30,y[i]-30,60,60);
		}
	}

	/* The following five methods must be implemented if  */
	/* the class "implements MouseListener".              */
	public void mousePressed(MouseEvent k) {} //do nothing
	public void mouseReleased(MouseEvent k) {} //do nothing
	public void mouseEntered(MouseEvent k) {} //do nothing
	public void mouseExited(MouseEvent k) {} //do nothing
	public void mouseClicked(MouseEvent k){
		x[n] = k.getX();  //save each mouse click location
		y[n] = k.getY();
		n++;              //and count them
		//This msg is displayed in the window when paint() is done.
        	msg = "X="+x[n-1]+"  Y="+y[n-1]+".";
		//This statement writes the message on the console
		repaint();
	}
}

