2010-07-15 64 views
-1
public void windowClosing(WindowEvent e) 
{ 
    if(e.getSource() == getFrame().?????) 
    { 
     //System.exit(0); 
    } 
    else 
    { 
     // do something another; 
    } 
} 

我想問的是什麼「?????」是?得到windows'什麼?什麼是「?????」在windowClosing(WindowEvent e)中?

+1

如果你會說出你遇到的這種情況,那麼這將對你有所幫助...... – 2010-07-15 15:20:22

+1

這在Java中無效。你在哪裏找到這個? – Thomas 2010-07-15 15:20:36

+1

@Thomas,他想知道在用'?????'標記的地方使用什麼方法或字段, – 2010-07-15 15:26:29

回答

1

它看起來像代碼試圖檢查窗口關閉事件的源是應用程序的「主」Frame,如果是,則返回System.exit(0)(目前已被註釋掉)。

java.awt.Frame.getFrames()它返回由該應用程序創建的所有Frame的數組。還有com.javaranch.common.AWT.getFrame(Component c)這顯然是一個非標準的庫方法。

無論如何,目前還不清楚getFrame() -etc是否有必要。根據出現此方法的上下文,右側可能只是this,或者可能是Frame.this。後一種語法稱爲「合格this」表達式,可以從內部類(通常用作事件偵聽器)中使用該表達式來引用封閉類的this實例。

相關問題