6.2. Handling events with UiBinder

Event handling in Java is ugly, and when writing an event handler Java provides limited options. You could create a new class to handle the event, possibly have your class implement the method, or write a nasty-looking anonymous class. With the first option you wind up with a ton of classes in your project. With the second you’re limited to handling one of each event type (that is, one onClick() method). And the third is why Ruby developers snicker when they look at Java code. To give you a visual of what we’re referring to, take a look at this example. The following shows a simple ClickHandler that will display an alert that says “Hello” when the myButton widget is clicked:

Button myButton = new Button("Click ...

Get GWT in Action, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.