TestJFrameImplementWindowListener extends JFrame implements WindowListener

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值