对窗口进行操作,将操作步骤显示在控制台
package chapter16;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;
@SuppressWarnings("serial")
public class TestWindowEvent extends JFrame {
public TestWindowEvent (){
addWindowListener(new WindowListener() {//匿名内部类
@Override
public void windowOpened(WindowEvent e) {
System.out.println("打开");
}
@Override
public void windowIconified(WindowEvent e) {
System.out.println("最小化");
}
@Override
public void windowDeiconified(WindowEvent e) {
System.out.println("最大化");
}
@Override
public void windowDeactivated(WindowEvent e) {
System.out.println("deactivate");
}
@Override
public void windowClosing(WindowEvent e) {
System.out.println("正在关闭");
}
@Override
public void windowClosed(WindowEvent e) {
System.out.println("closed");
}
@Override
public void windowActivated(WindowEvent e) {
System.out.println("activate");
}
});
}
public static void main(String[] args) {
JFrame frame = new TestWindowEvent();
frame.setTitle("loancalculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.pack();
frame.setSize(300, 300);
}
}
对窗口进行操作
显示在控制台中