2012-06-10 14 views
5

から所有者クラスに呼び出す -は以下のクラスを持つリスナー

public class GUIclass1 extends org.eclipse.swt.widgets.Composite { 
    private void initGUI() { 

     { 
      // The setting of the open file button. 
      openButton = new Button(this, SWT.PUSH | SWT.CENTER); 
      openButton.addSelectionListener(new SelectionAdapter() { 
       public void widgetSelected(SelectionEvent evt) { 
        foo() ; 
       } 
      }); 
     } 
    } 

    public void foo() { 
     // implementation .. 
    } 
} 

あなたが方法foo()への呼び出しがあるaddSelectionListener以内に見ることができるように。

私の質問は - foo()のプレフィックスとして、どのクラスに関連するのかを知るために書くべきです。

私はsuper().foo()を試しましたが、成功しませんでした。

答えて

8

あなたは私たちが知っているように、GUIclass1.this.foo()

0

これを試してみてくださいとして

それを呼ぶだろうan inner class has an implicit access to the members of the outer class、 のでthis.foo() Will NOT work、しかし

GUIclass1.this.foo() Will WORKいます。

関連する問題