Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling to the owner class from a listener

Having the follow class -

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

As you can see within the addSelectionListener there is a calling to method foo() .

My question is - which reference I should write as a prefix to foo() in order to know which class foo() related to .

I tried super().foo() with no success.

like image 732
URL87 Avatar asked Jun 10 '12 14:06

URL87


People also ask

What is the purpose of using listener class?

Listener Classes get notified on selected events, such as starting up the application or creating a new Session.

How do you call a class from a string?

You can do this using this code: Class clazz = Class. forName(yourString); As the class name you should use the full class name including packages.


1 Answers

You would call it as GUIclass1.this.foo()

like image 93
Aleks G Avatar answered Sep 19 '22 23:09

Aleks G