JavaSE series code 52: Application of window event class WindowEvent

regular expression
A regular expression is a string containing some special characters, which are called metacharacters in regular expressions. For example, \ \ D in “\ \ DOK” is a special metacharacter, representing any one of 0 to 9. A regular expression is also called a pattern. The strings “9OK” and “1ok” are both strings matching the pattern: “\ \ DOK”. A string that matches a pattern is called a match pattern string, also known as a pattern match string.

import java.awt.*; 
import java.awt.event.*; 
public class Javase_51 extends Frame  //定义主类
{
  static Label lab=new Label();
  static app13_6 frm=new app13_6();
  static MyWinListener winlist= new MyWinListener();
  public static void main(String[] args)
  {
    frm.setLayout(null);     //取消页面设置
    frm.setTitle("窗口事件");
    frm.setBounds(120,50,215,100);
    lab.setBounds(25,25,150,50);
    frm.add(lab);
    frm.addWindowListener(winlist);   //设置winlist为frm的事件监听者
    frm.setVisible(true);
  }
  //定义静态内部类MyWinListener并实现WindowListener接口
  static class MyWinListener implements WindowListener
  {
    public void windowOpened(WindowEvent e)    //打开窗口时的处理操作
     { lab.setText("打开新窗口"); }
    public void windowActivated(WindowEvent e)   //激活窗口时的处理操作
     { lab.setText("窗口被激活"); }
    public void windowIconified(WindowEvent e)  //窗口最小化时的处理操作
     { frm.setTitle("窗口被最小化"); }
    public void windowDeiconified(WindowEvent e)  //还原窗口时的处理操作
     { frm.setTitle("窗口被还原成正常大小"); }
    public void windowClosing(WindowEvent e)     //关闭窗口时的处理操作
    {
      frm.dispose();      //关闭窗口并释放资源
      System.exit(0);     //程序正常结束
    }
    public void windowDeactivated(WindowEvent e)  //窗口失活时的处理操作
     {    }     //空操作
    public void windowClosed(WindowEvent e)      //窗口关闭后的处理操作
     {    }     //空操作
  }
}
Published 52 original articles · Like 162 · Visitors 10,000+

Guess you like

Origin blog.csdn.net/blog_programb/article/details/105395092