[英]How to implement GWT, Java, button, and the clickhandler
Forgive me if this question has been asked and answered, as I have been unable to find it if it has. 如果有人提出并回答了这个问题,请原谅我,因为我一直找不到它。
I can find several examples like 我可以找到几个例子
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
... stuff ...
}
});
I'm trying to understand how to implement a button click handler using the following structure. 我正在尝试了解如何使用以下结构实现按钮单击处理程序。
public class myClass implements EntryPoint {
final Button MyButton = new Button("text");
:
:
void onClickMyButton(???) {
... stuff ...
}
:
:
}
To "me", this structure is more easily read and is just my preference in coding style. 对于“我”,此结构更易于阅读,而这只是我对编码样式的偏爱。 But I don't know how to implement it.
但是我不知道如何实现它。
I'm using Eclipse and GWT for a Java Web App. 我将Eclipse和GWT用于Java Web App。 Any help would be appreciated.
任何帮助,将不胜感激。
Either 要么
public class myClass implements EntryPoint, ClickHandler {
final Button myButton = new Button("text");
:
:
myButton.addClickHandler(this);
@Override
void onClick(ClickEvent event) {
... stuff ...
}
}
or 要么
public class myClass implements EntryPoint {
final Button myButton = new Button("text");
:
:
myButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
onClickMyButton(event);
}
});
private void onClickMyButton(ClickEvent event) {
... stuff ...
}
}
The second one is much cleaner, and allows handling several buttons with separate methods. 第二个更加清洁,并且允许使用单独的方法处理多个按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.