您的位置:首页 > 编程语言 > Java开发

【JAVA语言程序设计基础篇】--事件驱动程序设计--窗口事件

2016-12-31 23:54 309 查看

对窗口进行操作,将操作步骤显示在控制台

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);
}

}


对窗口进行操作

显示在控制台中
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐