public class DiceGame extends EFrame { private java.util.Random randy = new java.util.Random(); // 1 private ETimer one = new RollTimer(); // 2 private ETimer two = new RollTimer(); // 3 /** The View: Lay out the GUI components. */ public DiceGame() { super ("Dice Game", 530, 130, true); // 4 add (new GoButton().text ("Click to roll the 2 dice"));// 5 add (one.picture ("1die.jpg")); // 6 add (two.picture ("1die.jpg")); // 7 add (new StopButton().text ("Click to stop")); // 8 setVisible (true); // 9 } //====================== /** Controllers: React to click of button or ENTER key. */ private class GoButton extends EButton { public void onClick() { int n = 1 + randy.nextInt (6); //10 one.delay (150).picture (n + "die.jpg"); //11 n = 1 + randy.nextInt (6); //12 two.delay (90).picture (n + "die.jpg"); //13 } } //====================== private class RollTimer extends ETimer { public void onBeep() { int n = this.getPicture().charAt (0) - '0'; //14 n = (n >= 6 ? 1 : 1 + n); //15 this.delay (120).picture (n + "die.jpg"); //16 } } //====================== private class StopButton extends EButton { public void onClick() { one.stop(); //17 two.stop(); //18 } } //====================== } class DiceGameApp { public static void main (String[ ] args) { new DiceGame(); } //====================== }