开发者

Java - Call the main class (this) when i'm am into a method

I don't know how to do this (yes sorry, should be a must to know maybe). It would be easy to explain with an example :

public class PageMenuLogin extends Container {
    public PageMenuLogin() {
        final ITextField login_user = this.createTextField();
        login_user.setName("");

        final ITextField login_pass = this.createTextField();
        login_pass.setName("");

        final IButton button = this.createButton();
        button.setLabel("Login");
        button.setActionHandler(new IActionHandler() {
            public ClientActions onAction() throws Exception {
   开发者_运维问答             // I NEED TO UPDATE THE CONTAINER ITSELF HERE.
                // HOW CAN I CALL "this"?
                return null;
            }
        });
    }
}

As you can see in the example, i need to call the "this" when i'm into that method. I think everybody in java but markzzz know how to do this :)


PageMenuLogin.this?


when you create a object like this

button.setActionHandler(new IActionHandler() {
            public ClientActions onAction() throws Exception {
                // I NEED TO UPDATE THE CONTAINER ITSELF HERE.
                // HOW CAN I CALL "this"?
                return null;
            }
 });

You created a anonymous class(a class without name), take a look in binary class file dir, you'll see some class has name like PageMenuLogin$1.class, PageMenuLogin$2.class ... they are binary code of anonymous class. A anonymous class, Inner class can access its parent(top level) class object using syntax just as Tom's answer.


PageMenuLogin.this

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜