第11章 GUI 13 WindowEvent and 匿名类
鱼欲遇雨:每日都学习一点,持之以恒,天道酬勤!不能用电脑时,提前补上!(2012.9.16)
Window事件
3 与WindowListener对应的适配器为WindowAdapter
// TestWindowClose.javaimport java.awt.*;import java.awt.event.*;public class TestWindowClose {public static void main(String args[]) {new MyFrame55("MyFrame");}}class MyFrame55 extends Frame {MyFrame55(String s) {super(s);setLayout(null);setBounds(300, 300, 400, 300);setBackground(new Color(204, 204, 255));setVisible(true);//addWindowListener(new MyWindowMonitor());addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {setVisible(false);System.exit(0);}});}/*class MyWindowMonitor extends WindowAdapter {public void windowClosing(WindowEvent e) {setVisible(false);System.exit(0);}}*/}