java 最小化 最大化窗口 触发事件

  1. import javax.swing.*;   
  2. import java.awt.event.*;   
  3.   
  4. public class TestPost {   
  5.     JFrame mainFrame;   
  6.   
  7.     public TestPost() {   
  8.         mainFrame = new JFrame("JFrameDemo Title"); // 创建一个JFrame   
  9.         mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置关闭动作   
  10.         mainFrame.setSize(300300);// 设置窗口大小   
  11.         mainFrame.setLocationRelativeTo(null);// 使窗口显示在屏幕中央   
  12.   
  13.         mainFrame.addWindowListener(new WindowListener() {   
  14.             public void windowOpened(WindowEvent e) {   
  15.                 System.out.println("window opened");   
  16.             }   
  17.   
  18.             public void windowClosing(WindowEvent e) {   
  19.                 System.out.println("window closing");   
  20.             }   
  21.   
  22.             public void windowClosed(WindowEvent e) {   
  23.                 System.out.println("window closed");   
  24.             }   
  25.   
  26.             public void windowIconified(WindowEvent e) {   
  27.                 System.out.println("window iconified");   
  28.             }   
  29.   
  30.             public void windowDeiconified(WindowEvent e) {   
  31.                 System.out.println("window deiconified");   
  32.             }   
  33.   
  34.             public void windowActivated(WindowEvent e) {   
  35.                 System.out.println("window activated");   
  36.             }   
  37.   
  38.             public void windowDeactivated(WindowEvent e) {   
  39.                 System.out.println("window deactivated");   
  40.             }   
  41.         });   
  42.         mainFrame.addWindowFocusListener(new WindowFocusListener() {   
  43.             public void windowGainedFocus(WindowEvent e) {   
  44.                 System.out.println("gained focus");   
  45.             }   
  46.   
  47.             public void windowLostFocus(WindowEvent e) {   
  48.                 System.out.println("lost focus");   
  49.             }   
  50.         });   
  51.         mainFrame.addWindowStateListener(new WindowStateListener() {   
  52.             public void windowStateChanged(WindowEvent e) {   
  53.                 System.out.println("state changed");   
  54.             }   
  55.         });   
  56.   
  57.         mainFrame.setVisible(true);   
  58.     }   
  59.   
  60.     public static void main(String[] args) {   
  61.         new TestPost();   
  62.     }   
  63. }  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值