FileDocCategorySizeDatePackage
Radii.javaAPI DocExample1274Wed Aug 02 11:41:40 BST 2000None

Radii.java

import java.awt.*;		// make the graphics libraries available
import java.applet.*;	// make the applet libraries available
import java.util.*;		// make the random number library available

public class Radii extends Applet	// make a new applet
{
	private int counter;					// declare loop control variable
	private int stopValue;				// used to hold loop termination value
	final private int x1Coord = 10;	// declare and initialise x1Coord constant
	final private int y1Coord = 10;	// declare and initialise y1Coord constant
	final private int x2Coord = 250;	// declare and initialise x2Coord constant
	
	public void paint(Graphics g)
	{
		stopValue = (int)(Math.random() * 20 + 1); // generate a random termination value
		counter = 1;						// initialise the loop control variable
		while (counter <= stopValue)			// loop 10 times
		{
			if (counter % 2 == 0)		// if counter is an even number
			{
				g.setColor(Color.blue); // set drawing colour blue
			}
			else								// this is an odd number
			{
				g.setColor(Color.red);  // set drawing colour red
			}
			g.drawLine(x1Coord, y1Coord, x2Coord, counter * 10);
			counter = counter + 1;		// increment the loop control variable
		}
		g.drawString(stopValue + " Nice lines", 20, 260);
	}
}