package com.han;
import java.awt.Frame;
import java.awt.event.WindowEvent;
import java.awt.event.WindowStateListener;
import javax.swing.JFrame;
/**
* 捕获窗口状态事件
* @author HAN
*
*/
public class WindowEvent_2 extends JFrame {
/**
*
*/
private static final long serialVersionUID = -2809729177140674307L;
public WindowEvent_2() {
// TODO Auto-generated constructor stub
addWindowStateListener(new WindowStateListener() {
@Override
public void windowStateChanged(WindowEvent e) {
// TODO Auto-generated method stub
int oldState = e.getOldState();
int newState = e.getNewState();
String from = null;
String to;
switch (oldState) {
case Frame.NORMAL:
from = "正常化";
break;
case Frame.MAXIMIZED_BOTH:
from = "最大化";
break;
case Frame.ICONIFIED:
from = "图标化";
break;
}
switch (newState) {
case Frame.NORMAL:
to = "正常化";
break;
case Frame.MAXIMIZED_BOTH:
to = "最大化";
break;
default:
to = "图标化";
break;
}
System.out.println(from + "---->" + to);
}
});
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WindowEvent_2 frame = new WindowEvent_2();
frame.setTitle("捕获窗口状态事件");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(0, 0, 300, 100);
}
}
Java捕获窗口状态事件
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:什么是中间件(转)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
java检测当前CPU负载状态
java检测当前CPU负载状态的方法详解。
java System Windows linux -
事件捕获_事件冒泡
件冒泡和事件捕获的demo了无标题文档 事件的eventPhase说明了事件执
html 父节点 子节点