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;
	
}



你可能感兴趣的:(BasicKnowledge)