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

📄 windowlistenerdemo.java

📁 《java事件处理指南》一书的代码,好东西
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -