2013-05-15 71 views
0

WindowListener是一個接口?但是,如何實例化是有效的,如下所示?我們不能實例化接口嗎?是否有效實例化windowListener接口?

WindowListener l1=new WindowListener() { 

     public void windowOpened(WindowEvent e) { 
      // TODO Auto-generated method stub 

     } 

     public void windowIconified(WindowEvent e) { 
      // TODO Auto-generated method stub 

     } 

     public void windowDeiconified(WindowEvent e) { 
      // TODO Auto-generated method stub 

     } 

     public void windowDeactivated(WindowEvent e) { 
      // TODO Auto-generated method stub 

     } 

     public void windowClosing(WindowEvent e) { 
      // TODO Auto-generated method stub 

     } 

     public void windowClosed(WindowEvent e) { 
      // TODO Auto-generated method stub 

     } 

     public void windowActivated(WindowEvent e) { 
      // TODO Auto-generated method stub 

     } 
    }; 
+0

請參閱[*如何編寫窗口監聽器*](http://docs.oracle.com/javase/tutorial/uiswing/events/windowlistener.html) – trashgod

回答

0

這是創建一個實現WindowListener接口的新匿名類。

+0

感謝您的回覆。 然後,對於以下內容,擴展WindowAdapter的新匿名類? WindowListener l = new WindowAdapter(){ \t \t \t public void windowClosing(WindowEvent e){ }我是否正確? – Rose