public class MathQuiz extends EFrame { /** The View: Lay out the GUI components. */ public MathQuiz() { add (new ELabel().text ("Is 121 a perfect square?")); // 1 add (new YesRightButton().text ("yes")); // 2 add (new NoWrongButton().text ("no")); // 3 add (new ELabel().text ("What is the square of 30?")); // 4 add (new AnswerField().width (8)); //in characters // 5 add (new ELabel().picture ("Rome.jpg")); // 6 setVisible (true); // 7 } //====================== /** Controllers: React to click of button or ENTER key. */ private class YesRightButton extends EButton { public void onClick() { this.setText ("right!"); // 8 } } //====================== private class NoWrongButton extends EButton { public void onClick() { this.setText ("you're wrong."); // 9 } } //====================== private class AnswerField extends EField { public void onEnter() { if (this.getText().equals ("900")) //10 this.setText ("good!"); //11 else //12 this.setText ("you're wrong."); //13 } } //====================== } class MathQuizApp // to create a frame from the command window { public static void main (String[ ] args) { new MathQuiz(); } //====================== }