public class AWTApplication
class Model
1: // AWTApplication.java
2: // A "shell" for a simple AWT-based application
4: import java.awt.*;
5: import java.awt.event.*;
8: public class AWTApplication
9: extends Frame
10: implements ActionListener, WindowListener
11: {
12: // Put instance variables here, such as ...
13: private Button aButton;
14: private Scrollbar aScrollbar;
15: private Model aModelInstance;
18: public static void main(String [] args)
19: {
20: AWTApplication anInstance = new AWTApplication();
21: anInstance.setSize(300, 200);
22: anInstance.setVisible(true);
23: }
26: // Constructor
27: public AWTApplication()
28: {
29: aButton = new Button("Press Me");
30: add(aButton);
31: aButton.addActionListener(this);
32: aModelInstance = new Model();
33: this.addWindowListener(this); // for windowClosing event
34: }
37: public void paint(Graphics g)
38: {
39: aModelInstance.display(g);
40: }
43: public void actionPerformed(ActionEvent event)
44: {
45: if(event.getSource() == aButton)
46: {
47: // Code to respond to button being pressed.
48: // For example ...
49: aModelInstance.getSomething();
50: }
51: }
54: // Implementation of the WindowListener interface
55: public void windowClosing(WindowEvent e)
56: {
57: System.exit(0);
58: }
59: // Empty WindowListener methods
60: public void windowIconified(WindowEvent e) {}
61: public void windowOpened(WindowEvent e) {}
62: public void windowClosed(WindowEvent e) {}
63: public void windowDeiconified(WindowEvent e) {}
64: public void windowActivated(WindowEvent e) {}
65: public void windowDeactivated(WindowEvent e) {}
66: }
70: class Model
71: {
72: // Put (private) instance variables here ...
74: public void setSomething()
75: {
76: // Code ...
77: }
79: public void getSomething()
80: {
81: // Code ...
82: }
84: public void display(Graphics g)
85: {
86: // Code to display current state
87: }
88: }