import java.awt.*; // make the graphics libraries available
import java.applet.*; // make the applet libraries available
import java.util.*; // make the maths random number available
public class dice extends Applet // create a new applet
{
int firstDice;
int secondDice;
int loopCount;
public void paint(Graphics g)
{
loopCount = 0;
do
{
loopCount = loopCount + 1;
g.drawString("Attempt number:...> " + loopCount, 100, 100);
firstDice = (int)(Math.random() * 6 + 1);
secondDice = (int)(Math.random() * 6 + 1);
g.setColor(Color.magenta);
g.fillRect(80, 120, 60, 60);
g.setColor(Color.yellow);
g.fillRect(160, 120, 60, 60);
g.setColor(Color.blue);
g.drawString("" + firstDice, 107, 153);
g.drawString("" + secondDice, 187, 153);
for (int count = 0; count < 1000; count++)
{
g.drawString(" ", 200, 100);
}
} while (firstDice != secondDice);
g.drawString("Congratulations - you've won", 80, 200);
}
} |