事件:继承某个类和不继承某个类

import  java.awt. * ;
import  java.awt.event. * ;

public   class  WindowDemo  implements  WindowListener  {
    
public WindowDemo(){
        Frame f 
= new Frame("Window test");    //注意这一块
        f.setSize(300,300);
        f.setVisible(
true);
        f.addWindowListener(
this);
    }

    
public static void main(String args[]) {
        
new WindowDemo();
    }

     
     
public void windowActivated(WindowEvent e) {
     }

     
public  void windowClosed(WindowEvent e) {
     }

      
public void windowClosing(WindowEvent e) {
          System.exit(
0);
     }

     
public  void windowDeactivated(WindowEvent e) {
     }

       
public void windowDeiconified(WindowEvent e) {
      }

       
public void windowIconified(WindowEvent e)  {
      }
   
     
public  void windowOpened(WindowEvent e) {
     }

}
 
import  java.awt. * ;
import  java.awt.event. * ;

public   class  WinListenerDemo  extends  Frame  implements  WindowListener {
    
public WinListenerDemo() {
        
super("Adapter demo");   //注意这一块
        this.setSize(300,300);
        
this.setVisible(true);
        
this.addWindowListener(this);
    }

    
public static void main(String args[]) {
        
new WinListenerDemo();
    }

    
    
public void windowActivated(WindowEvent e) {
    }

    
public void windowClosed(WindowEvent e)  {
    }

    
public void windowClosing(WindowEvent e)  {
        
this.dispose();
        System.exit(
0);        
    }

    
public void windowDeactivated(WindowEvent e) {
    }

    
public void windowDeiconified(WindowEvent e) {
    }

    
public void windowIconified(WindowEvent e)  {
    }

    
public void windowOpened(WindowEvent e) {
    }

}

 

 

你可能感兴趣的:(事件:继承某个类和不继承某个类)