2012-06-10 9 views
5

Tener la clase de seguimiento -Llamando a la clase propietario de un oyente

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 .. 
    } 
} 

Como se puede ver en el addSelectionListener hay una llamada al método de foo().

Mi pregunta es - qué referencia debería escribir como un prefijo a foo() para saber qué clase foo() se relaciona con.

Intenté super().foo() sin éxito.

Respuesta

8

Se podría llamar como GUIclass1.this.foo()

0

Prueba de esto,

Como sabemos que an inner class has an implicit access to the members of the outer class, por lo this.foo() Will NOT work, pero

GUIclass1.this.foo() Will WORK.

Cuestiones relacionadas