FileDocCategorySizeDatePackage
Circles.javaAPI DocExample958Wed Oct 04 14:10:32 BST 2000None

Circles.java

import java.awt.*;
import java.applet.*;

public class Circles extends Applet
{
	private int counter;			// loop control variable
	private int stopValue;		// loop termination variable
	private int xCoord = 150;
	private int yCoord = 150;
	int diameter;
	final int change = 20;
	
	public void paint(Graphics g)
	{
		int numCircles;
		stopValue = 1;
		counter = (int)(Math.random() * 15 + 1);
		numCircles = counter;
		xCoord = xCoord - counter * (change / 2);
		yCoord = yCoord - counter * (change / 2);
		while (counter >= stopValue)
		{
			diameter = counter * change;

		   if (counter % 2 == 0)
		   {
		   	g.setColor(Color.blue);
			}
			else
			{
				g.setColor(Color.red);
			}
			g.fillOval(xCoord, yCoord, diameter, diameter);
			counter = counter - 1;
			xCoord = xCoord + change / 2;
			yCoord = yCoord + change / 2;
		}
		g.drawString(numCircles + " Nice circles", change, counter * diameter + change);
	}
}