windowlistenerdemo.java
来自「《java事件处理指南》一书的代码,好东西」· Java 代码 · 共 76 行
JAVA
76 行
import java.awt.*;import java.awt.event.*;import javax.swing.*;public class WindowListenerDemo extends JFrame implements WindowListener{ private JFrame frame1, frame2; private JTextField jtf; public WindowListenerDemo() {/* A secondary JFrame is created and made visible. The frame *//* registers a WindowListener. */ frame1 = new JFrame("Child Window"); frame1.setBounds(400, 150, 200, 100); frame1.setVisible(true); frame1.addWindowListener(this); jtf = new JTextField(20); jtf.setEditable(false); getContentPane().add(jtf, BorderLayout.SOUTH); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 300, 200); setVisible(true); }/* The WindowListenerDemo class serves as the WindowListener so *//* it must provide implementation of the methods declared in the *//* WindowListener interface. These methods are written so as to *//* indicate the status of the child frame. */ public void windowActivated(WindowEvent event) { jtf.setText("Child window now active"); } public void windowClosed(WindowEvent event) { jtf.setText("Child window closed"); } public void windowClosing(WindowEvent event) { jtf.setText("Child window closing"); } public void windowDeactivated(WindowEvent event) { jtf.setText("Child window no longer active"); } public void windowDeiconified(WindowEvent event) { jtf.setText("Child window de-iconified"); } public void windowIconified(WindowEvent event) { jtf.setText("Child window iconified"); } public void windowOpened(WindowEvent event) { jtf.setText("Child window opened"); } public static void main(String args[]) { WindowListenerDemo demo = new WindowListenerDemo(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?