public class CommandForm extends Form implements CommandListener {
Display d;
public CommandForm(String msg) {
super(msg);
this.addCommand(exit);
}
private void showMessage(String title, String text) {
Alert a = new Alert(title, text, null, AlertType.INFO);
d.setCurrent(a, this);
}
public void prepare_view(Display d){
this.setCommandListener(this);
this.d = d;
}
public void show_view(){
d.setCurrent(this);
}
}
我不知道这个例子中“this”关键字的确切含义。我的讲师说它是当前对象,当我进一步询问时,他说它是 CommandForm。那是对的吗?当您将'this' 传递到括号中时,例如setCommandListener(this),您实际上是在传递CommandForm 吗?我知道如何使用“this”的唯一方法就是这样,this.d = d。所以这对我来说有点新鲜。