TestJFrameImplementWindowListener extends JFrame implements WindowListener

论坛 期权论坛 脚本     
匿名技术用户   2021-1-2 11:48   68   0
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;

public class TestJFrameImplementWindowListener extends JFrame implements WindowListener
{
 private static final long serialVersionUID = 1L;
 public TestJFrameImplementWindowListener()
 {
  // TODO Auto-generated constructor stub
  //必须使用addWindowListener(this),否则不监听。
  addWindowListener(this);
 }

 @Override
 public void windowOpened(WindowEvent e)
 {
  // TODO Auto-generated method stub
  System.out.println("TestFrame.windowOpened()");
 }

 @Override
 public void windowClosing(WindowEvent e)
 {
  // TODO Auto-generated method stub
  System.out.println("TestFrame.windowClosing()");
 }

 @Override
 public void windowClosed(WindowEvent e)
 {
  // TODO Auto-generated method stub
  System.out.println("TestFrame.windowClosed()");
 }

 @Override
 public void windowIconified(WindowEvent e)
 {
  // TODO Auto-generated method stub
  System.out.println("TestFrame.windowIconified()");
 }

 @Override
 public void windowDeiconified(WindowEvent e)
 {
  // TODO Auto-generated method stub
  System.out.println("TestFrame.windowDeiconified()");
 }

 @Override
 public void windowActivated(WindowEvent e)
 {
  // TODO Auto-generated method stub
  System.out.println("TestFrame.windowActivated()");
 }

 @Override
 public void windowDeactivated(WindowEvent e)
 {
  // TODO Auto-generated method stub
  System.out.println("TestFrame.windowDeactivated()");
 }
 
}

JobRun:

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class JobRun
{
 static void runTestJFrame()
 {
  TestJFrame testJFrame=new TestJFrame();
  testJFrame.setSize(300,200);
  testJFrame.setVisible(true);
  testJFrame.setLocationRelativeTo(null);
  testJFrame.addWindowListener(new WindowAdapter()
  {
   @Override
   public void windowClosing(WindowEvent e)
   {
    // TODO Auto-generated method stub
    System.out.println("JobRun.main(...).new WindowAdapter() {...}.windowClosing()");
    //super.windowClosing(e);
    System.exit(0);
   }
  });
 }
 
 static void runTestJFrameImplementWindowListener()
 {
  TestJFrameImplementWindowListener testJIW=new TestJFrameImplementWindowListener();
  testJIW.setTitle("w3ang");
  testJIW.setSize(300,200);
  testJIW.setVisible(true);
  testJIW.setLocationRelativeTo(null);
 }
 
 public static void main(String[] args)
 {
  System.out.println("JobRun.main()");
  //runTestJFrame();
  runTestJFrameImplementWindowListener();
 }
}

TestJFrame:

import javax.swing.JFrame;

public class TestJFrame extends JFrame
{

 private static final long serialVersionUID = 1L;
 
}



分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP