I assume that the part you came across is an anonymous class. What happens here is that you call the addClickHandler method on the helloBtn object and pass it an instance of the anonymous class.
The addClickHandler method takes an instance of ClickHandler as an argument. The following code creates an anonymous class that implements the ClickHandler interface.
new ClickHandler() { public void onClick(ClickEvent event) { Window.alert("Hello!"); }
You can imagine rewriting code by first defining a class.
public class MyClickHandler implements ClickHandler { public void onClick(ClickEvent event) { Window.alert("Hello!"); } }
Then create an instance of the class and pass it to the addClickHandler method.
ClickHandler myClickHandler = new MyClickHandler(); helloBtn.addClickHandler(myClickHandler);
source share