01: import java.awt.*;
02: import java.awt.event.*;
03:
04: public class GUIaa extends Frame {
05: Button b0 = new Button("Even/Odd?");
06: Label x0 = new Label("Type a number and press...");
07: TextField t0 = new TextField();
08:
09: public GUIaa() {
10: setLayout(null);
11: add(t0); t0.setBounds(10, 40, 90, 30);
12: add(b0); b0.setBounds(110, 40, 90, 30);
13: add(x0); x0.setBounds(10, 80, 180, 30);
14: b0.addActionListener(new ActionListener() {
15: public void actionPerformed(ActionEvent evt) {
16: int i = (new Integer(t0.getText())).intValue();
17: t0.setText("");
18: if(i % 2 == 0) {
19: x0.setText(i + " is Even");
20: } else {
21: x0.setText(i + " is Odd");
22: }
23: }
24: });
25: }
26: public static void main(String[] args) {
27: Frame win = new GUIaa();
28: win.setSize(200, 150); win.setVisible(true);
29: win.addWindowListener(new WindowAdapter() {
30: public void windowClosing(WindowEvent evt) {
31: System.exit(0);
32: }
33: });
34: }
35: }
|