标签:
对窗口进行操作,将操作步骤显示在控制台
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); } }
显示在控制台中
【JAVA语言程序设计基础篇】--事件驱动程序设计--窗口事件
标签:
原文地址:http://blog.csdn.net/qq_24653023/article/details/52214449