import awb.*; import java.awt.*; import java.awt.event.*; public class AboveBelow extends java.applet.Applet implements ActionListener { TextField m1, m2; IntField i1; Button b1, b2; int secret, guess; public void init () { m1 = new TextField(80); m1.setText("Enter number between 0 and 100 below, then push SECRET"); i1 = new IntField(40); m2 = new TextField(80); b1 = new Button("SECRET"); b2 = new Button("GUESS"); add(m1); add(b1); add(i1); add(b2); add(m2); b1.addActionListener(this); b2.addActionListener(this); } public void actionPerformed(ActionEvent event) { Object cause = event.getSource(); if (cause == b1) { secret = i1.getInt(); i1.setInt(); m1.setText("Now, enter your guess below, then press GUESS"); } if (cause == b2) { guess = i1.getInt(); if (guess == secret) { m2.setText("You've got it!"); } if (guess < secret) { i1.setInt(); m2.setText("The number is greater than "+guess); } if (guess > secret) { i1.setInt(); m2.setText("The number is less than "+guess); } } } }