Java 从侦听器调用所有者类
有跟班-Java 从侦听器调用所有者类,java,button,methods,swt,listener,Java,Button,Methods,Swt,Listener,有跟班- 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); openButt
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 ..
}
}
正如您可以在addSelectionListener
中看到的,有一个对方法foo()
的调用
我的问题是-我应该写哪个引用作为foo()
的前缀,以便知道与哪个类foo()
相关
我尝试了
super().foo()
,但没有成功 您可以将其称为GUIclass1.this.foo()
试试这个
正如我们所知,内部类可以隐式访问外部类的成员
,
因此,这个.foo()将不起作用
,但是
GUIclass1.this.foo()将起作用