📄 testwindowevent.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 + -