标题:Java捕获窗口状态事件
只看楼主
shitainong
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2012-7-6
结帖率:0
 问题点数:0 回复次数:0 
Java捕获窗口状态事件
Java捕获窗口状态事件



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("捕获窗口状态事件"); www.
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(0, 0, 300, 100);
}

}

搜索更多相关主题的帖子: long private package public import 
2012-07-13 15:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-373309-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015807 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved