窗口监听
package lesson03;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TextWindow {
public static void main(String[] args) {
new WindowFrame();
}
}
class WindowFrame extends Frame {
public WindowFrame() {
setVisible(true);
setBounds(100, 100, 100, 100);
setBackground(Color.red);
this.addWindowListener(
new WindowAdapter() {
//关闭窗口
@Override
public void windowClosing(WindowEvent e) {
System.out.println("关闭窗口");
System.exit(0);
}
@Override
public void windowActivated(WindowEvent e) {
System.out.println("激活窗口");
WindowFrame source = (WindowFrame) e.getSource();
source.setTitle("被激活了");
}
}
);
}
}
/* class MyWindowListener extends WindowAdapter{
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
*/