FileDocCategorySizeDatePackage
DiceRoll.javaAPI DocExample1461Fri Oct 12 10:58:28 BST 2001None

DiceRoll

public class DiceRoll extends Applet

Fields Summary
private int
firstDie
private int
secondDie
Constructors Summary
Methods Summary
public voidpaint(java.awt.Graphics g)

		firstDie  = (int) (Math.random() * 6) + 1; // get a value for the first dice
		secondDie = (int) (Math.random() * 6) + 1; //get a value for the second dice
										// draw the dice squares
		g.setColor(Color.blue);
		g.fillRect(20, 20, 60, 60);
		g.setColor(Color.magenta);
		g.fillRect(120, 20, 60, 60);
										// put the values on the dice
		g.setColor(Color.white);
		g.drawString(" " + firstDie, 43, 54);
		g.drawString(" " + secondDie, 143, 54);
										// write the values under the dice
		g.setColor(Color.black);
		g.drawString("First dice = " + firstDie, 20, 100); 
		g.drawString("Second Dice = " + secondDie, 120, 100); // print out the dice values