//File:	Circles3.java
//The following packages are necessary for any applet
import java.applet.*;
import java.awt.*;

//The following package is necessary if we are to have
//an interactive applet, one that responds to events
import java.awt.event.*;

public class Circles3 extends Applet implements ActionListener
{
	Button circleButton = new Button("New Circle");
	
	public void init()
	{
		//add the applet components here
		add (circleButton);
		circleButton.addActionListener(this);
		setBackground (Color.white);
	}
	
	//The paint() method is called by the browser whenever the applet must be redrawn
	public void paint (Graphics g)
	{
	    // Add an array for random colors
	    Color [] myColors = 
	    	{ Color.black, Color.blue, Color.cyan,
	    	  Color.darkGray, Color.gray, Color.green,
	    	  Color.lightGray, Color.magenta, Color.orange,
	    	  Color.pink, Color.red, Color.yellow };
		Dimension d=getSize();
		int w=d.width;
		int h=d.height;
		
		int x,y,radius;
		
		radius=25;
		x = (int) (w * Math.random());
		y = (int) (h * Math.random());
		
		// Set the color to one of the random colors
                g.setColor (myColors[((int)(12*Math.random()))%12]);
		g.fillOval(x-radius, y-radius, 2*radius, 2*radius);
	}
	
	//The actionPerformed() method from the ActionListener interface must be implemented
	public void actionPerformed (ActionEvent event) 
	{
		//Here is where the ActionListener components respond to events
		repaint();	//calls update()
	}
	
	public void update (Graphics g)
	{
		//Our update doesn't clear the window first
		paint(g);
	}
}
