public class MyDiceGame extends EFrame { private java.util.Random randy = new java.util.Random(); // 1 private ETimer one = new RollTimer(); // 2 private ETimer two = new RollTimer(); private ELabel totalLabel = new ELabel(); private int dTotal = 0; /** The View: Lay out the GUI components. */ public MyDiceGame() { super ("Dice Game", 530, 230, 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")); add (totalLabel); totalLabel.setText("Dice Total = 0"); 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"); n = 1 + randy.nextInt (6); //12 two.delay (90).picture (n + "die.jpg"); } } //====================== 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 (200).picture (n + "die.jpg"); } } //====================== private class StopButton extends EButton { public void onClick() { one.stop(); int n = one.getPicture().charAt (0) - '0'; dTotal = dTotal + n; two.stop(); n = two.getPicture().charAt (0) - '0'; dTotal = dTotal + n; totalLabel.setText ("Dice Total = " + dTotal);//18 } } //====================== } class MyDiceGameApp { public static void main (String[ ] args) { new MyDiceGame(); } //====================== }