窗口监听
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b38369eca012a0501347993400a889af.png)
package com.dong.lesson03;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TestWindow {
public static void main(String[] args) {
new WindowFrame();
}
}
class WindowFrame extends Frame {
public WindowFrame() {
setBackground(Color.MAGENTA);
setBounds(100, 100, 200, 200);
setVisible(true);
this.addWindowListener(
new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.out.println("windowClosing");
System.exit(0);
}
@Override
public void windowActivated(WindowEvent e) {
WindowFrame source = (WindowFrame) e.getSource();
source.setTitle("被激活了");
System.out.println("windowActivated");
}
});
}
}