⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testwindowevent.java

📁 此源码为机械工业出版社出版的《Java语言程序设计》第三版所配套的书中所有源代码。
💻 JAVA
字号:
// TestWindowEvent.java: Create a frame to test window events
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;

public class TestWindowEvent extends JFrame
  implements WindowListener
{
  // Main method
  public static void main(String[] args)
  {
    TestWindowEvent frame = new TestWindowEvent();
    // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setTitle("Test Window Event");
    frame.setSize(100, 80);
    frame.setVisible(true);
  }

  // Default constructor
  public TestWindowEvent()
  {
    super();
    addWindowListener(this);  // Register listener
  }

  /**
   * Handler for window deiconified event   * Invoked when a window is changed from a minimized   * to a normal state.   */  public void windowDeiconified(WindowEvent event)
  {
    System.out.println("Window deiconified");
  }

  /**
   * Handler for window iconified event   * Invoked when a window is changed from a normal to a   * minimized state. For many platforms, a minimized window   * is displayed as the icon specified in the window's   * iconImage property.   * @see Frame#setIconImage   */  public void windowIconified(WindowEvent event)
  {
    System.out.println("Window iconified");
  }

  /**
   * Handler for window activated event   * Invoked when the window is set to be the user's   * active window, which means the window (or one of its   * subcomponents) will receive keyboard events.   */  public void windowActivated(WindowEvent event)
  {
    System.out.println("Window activated");
  }

  /**
   * Handler for window deactivated event
   * Invoked when a window is no longer the user's active
   * window, which means that keyboard events will no longer   * be delivered to the window or its subcomponents.   */  public void windowDeactivated(WindowEvent event)
  {
    System.out.println("Window deactivated");
  }

  /**
   * Handler for window opened event   * Invoked the first time a window is made visible.   */  public void windowOpened(WindowEvent event)
  {
    System.out.println("Window opened");
  }

  /**
   * Handler for window closing event   * Invoked when the user attempts to close the window   * from the window's system menu.  If the program does not   * explicitly hide or dispose the window while processing   * this event, the window close operation will be cancelled.   */  public void windowClosing(WindowEvent event)
  {
    System.out.println("Window closing");
  }

  /**
   * Handler for window closed event   * Invoked when a window has been closed as the result   * of calling dispose on the window.   */  public void windowClosed(WindowEvent event)
  {
    System.out.println("Window closed");
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -