FileDocCategorySizeDatePackage
nestedCircles.javaAPI DocExample1015Tue Aug 08 17:24:44 BST 2000None

nestedCircles.java

import java.awt.*;			// use existing graphics code
import java.applet.*;		// use existing applet code

// Create an applet and draw a series of nested circles using a for loop.

public class nestedCircles extends Applet		// this is the applet
{
	private int circleXPosition ;  // set the x coordinate of the largest circle
	private int circleYPosition ;  // set the y coordinate of the largest circle
	private int diameter ;				  // the diameter of the circle
	
	public void paint(Graphics g)
	{	
		// initialise to position of largest circle									
		circleXPosition = 0 ;
		circleYPosition = 0 ;
		
		// set the colour
		g.setColor(Color.green) ;
		
		for (diameter = 200 ; diameter > 0 ; diameter -= 20)
		{
			// draw the circle for this iteration
			g.drawOval(circleXPosition,circleYPosition,diameter,diameter) ;
			
			// update the circle position ready for next time
			circleXPosition = circleXPosition + 10 ;
			circleYPosition = circleYPosition + 10 ;
			
		}
			
	}
}