| |
14. 81. 5. 确定何时框架或窗口打开或关闭 |
|
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class Main {
public static void main() {
Frame frame = new Frame();
WindowListener listener = new WindowAdapter() {
public void windowOpened(WindowEvent evt) {
Frame frame = (Frame) evt.getSource();
System.out.println(frame.getTitle());
}
public void windowClosing(WindowEvent evt) {
Frame frame = (Frame) evt.getSource();
System.out.println(frame.getTitle());
}
public void windowClosed(WindowEvent evt) {
Frame frame = (Frame) evt.getSource();
System.out.println(frame.getTitle());
}
};
frame.addWindowListener(listener);
frame.setVisible(true);
}
}
|
|
|