視窗事件

託帕發表於2018-09-19
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Test extends JFrame{

	Wdmb mb=null;

	public static void main(String[] args){

		Test lx=new Test();	
	}

	public Test(){

		mb=new Wdmb();
		this.add(mb);
		this.addWindowListener(mb);

		this.setSize(300,260);
		this.setLocation(300,280);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);	
	}

	class Wdmb extends JPanel implements WindowListener{
		public void paint(Graphics g){
			super.paint(g);			
		}

		public void windowOpened(WindowEvent e){
			System.out.println("視窗開啟");
		}

		public void windowClosing(WindowEvent e) {
			System.out.println("視窗關閉");		
		}

		
		public void windowClosed(WindowEvent e) {	
		}

		
		public void windowIconified(WindowEvent e) {
			System.out.println("最小化");
		}
	
		public void windowDeiconified(WindowEvent e) {
			System.out.println("從最小化變成正常");
		}

		
		public void windowActivated(WindowEvent e) {
			System.out.println("視窗被啟用");
		}

		
		public void windowDeactivated(WindowEvent e) {
		}

	}
}

 

相關文章