也没啥,就是之前讲过的
此外值得注意的点也就,匿名内部类的使用而已
package GUI;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Test12_Windows {
public static void main(String[] args) {
new WindowFrame();
}
}
class WindowFrame extends Frame {
public WindowFrame() {
setSize(500, 500);
setVisible(true);
addWindowListener(new WindowAdapter() {
// 常用的也就这两
@Override
public void windowClosing(WindowEvent e) {
System.out.println("windowClosing");
}
@Override
public void windowActivated(WindowEvent e) {
System.out.println("windowActivated");
}
/* 用不上的
@Override
public void windowOpened(WindowEvent e) {
System.out.println("windowOpened");
}
@Override
public void windowClosed(WindowEvent e) {
System.out.println("windowClosed");
}
*/
});
}
}
/*
// 这是内部类,还可以弄成匿名内部类(就不用想名字和担心名字重复)
class MyWindowListener extends WindowAdapter{
@Override
public void windowClosing(WindowEvent e) {
setVisible(false); // 隐藏当前窗口,但还存在
// System.exit(0);
}
}
}
*/
标签:12,窗口,void,System,public,WindowEvent,Override,监听,out
From: https://www.cnblogs.com/zhanjianhai/p/17620097.html