Not much to say. If you click on something in the list above, it fires
If you need more control (onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, onMouseMove) then look at the MouseListener
There are many ways to implement listeners. Here are five. Comments in the code
/************************************************************************** * The compact version - here the class *is* the listener. Fine if you * only want one method for anything that is clicked. Not necessarily as * easy to read as the listener doesn't have to be anywhere near the * button's code - 10 code lines */ class Demo1 extends Composite implements ClickListener { public Demo1() { initWidget(new Button("Demo 1", this)); } public void onClick(Widget sender) { Window.alert("Demo 1 click"); } } /************************************************************************** * The middling version - an anonymous listener just for this button. * You can have more listeners, but you can't reuse this one, it's not * as neat-looking as the other two, but you can't lose the related code - * 13 code lines */ class Demo2 extends Composite { public Demo2() { initWidget(new Button("Demo 2", new ClickListener() { public void onClick(Widget sender) { Window.alert("Demo 2 click"); } })); } } /************************************************************************** * A more flexible version - you can reuse the named listener and it's * not as deeply nested as Demo 2, and you can reuse the listener. Not * necessarily as easy to read as the listener doesn't have to be * anywhere near the button's code and you have to declare the listener * before using it - 14 lines of code */ class Demo3 extends Composite { public Demo3() { ClickListener listener = new ClickListener() { public void onClick(Widget sender) { Window.alert("Demo 3 click"); } }; initWidget(new Button("Demo 3", listener)); } } /************************************************************************** * A more flexible version - you can reuse the named listener and it's * not as deeply nested as Demo 2, and you can reuse the listener. Not * necessarily as easy to read as the listener can be even further away * from the button's code - you don't have to declare the listener * before using it - 14 lines of code */ class Demo4 extends Composite { public Demo4() { initWidget(new Button("Demo 4", listener)); } ClickListener listener = new ClickListener() { public void onClick(Widget sender) { Window.alert("Demo 4 click"); } }; } /************************************************************************** * The most flexible version - you can reuse the named listener in any * internal class, not necessarily as easy to read as the listener can * be anywhere in the top-level class - you don't have to declare the * listener before using it - 14 lines of code */ class Demo5 extends Composite { public Demo5() { initWidget(new Button("Demo 5", listener)); } } ClickListener listener = new ClickListener() { public void onClick(Widget sender) { Window.alert("Demo 5 click"); } };