File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes GWT and the fly likes Which checkbox was clicked? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » GWT
Bookmark "Which checkbox was clicked?" Watch "Which checkbox was clicked?" New topic

Which checkbox was clicked?

Laurence Turpin

Joined: May 21, 2012
Posts: 19

I'm using GWT 2.4 on Windows 7.
I am writing a program with 3 checkboxes
marked as Red Green and Blue.
Inside the onClick() method I wish to identify which checkbox was clicked.
The program I have at the moment is shown below:

Inside the Window.alert() method I wish to put the checkbox that was clicked, but do not know how to identify it.
It can be done with 3 different handler classes.
One for each checkbox but that does not seem to be an efficient way of doing it.
Has anyone any ideas?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10767

ClickEvent has a getSource() method which returns the event origin. In your case it will be a CheckBox. So, if you use this method you will need to type cast it to a CheckBox. Once you get the CheckBox, you can use the getText to see which check box was clicked.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Laurence Turpin

Joined: May 21, 2012
Posts: 19
Thank you Manesh Godbole for your reply which has solved my problem.
Below is the corrected program.

I agree. Here's the link:
subject: Which checkbox was clicked?
It's not a secret anymore!