• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Which checkbox was clicked?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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?
 
Bartender
Posts: 11445
18
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Laurence Turpin
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Manesh Godbole for your reply which has solved my problem.
Below is the corrected program.

 
These are the worst of times and these are the best of times. And this is the best tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!