import java.awt.*;
import java.awt.event.*;
public class TestFrame {
public static void main(String[] args) {
Frame f = new Frame("A Test Window");
f.setSize(320, 180);
f.setVisible(true);
f.addWindowListener(new WindowListener() {
public void windowClosing(WindowEvent e) {
System.out.println("我退出了!");
e.getWindow().setVisible(false);
((Window)e.getComponent()).dispose();
System.exit(0);
}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
});
}
}