0

I'm writing a simple SWT program, but I faced problem when adding a new listener:

public class MainMenu extends Shell {
    public MainMenu(Display display){
        // .......
        Button btLogin = new Button(this, SWT.PUSH);
        btLogin.setText("Login");
        btLogin.setLayoutData(data);
        btLogin.addSelectionListener(new SelectionAdapter() {
            public void WidgetSelected(SelectionEvent e) {
                MessageBox msg = new MessageBox(this);
                //              Problem here -> ^^^^
                msg.setText("");
                msg.setMessage("Success!");
                msg.open();
            }
        });
        // .......
    }
}

In the "this" shown in the code, I want to pass the MainMenu instance to constructor MessageBox, but simply passing "this" to the constructor doesn't work because the "this" here will be considered as reference to the anonymous class.

I have searched online for a while, and I found no solution. How do I do this?

0 Answers0