用户类继承自WindowAdapter,而窗口对象Frame作为用户类的数据成员.
1 import java.awt.*;
2 import java.awt.event.*;
3
4 public class FrameTest extends WindowAdapter{
5
6 Frame f = new Frame();
7 public void display()
8 {
9 f.setTitle("MyFrame");
10 f.setSize(480,200);
11 f.setLocation (200,400);
12 f.setBackground (Color.lightGray);
13 f.addWindowListener (this); //窗体f--注册窗体事件监听器
14 f.setVisible(true);
15 }
16
17 public void windowClosing(WindowEvent e)
18 {
19 System.exit(0);
20 }
21
22 public static void main (String args[])
23 {
24 new FrameTest().display();
25
26 }
27 }