i need your help to know which checkbox cause the event:
i have 2 checkboxes and 2 radiobutton (in swing),then i add the 2 checkboxes to a buttongroup and the 2 radiobutton to a buttongroup,so as default 1 checkbox and 1 radiobutton are selected,so when i check other radiobutton or other checkbox i want to change a string value,so what i need that to know which checkbox and which radiobutton caused the event because i can again check the original checkbox(default one).
thank very much.

Uhm, the getSource() method of the Event?

If you want two checkboxes to do different things, why dont you give them different actionListeners?

Or, you can pass an identifier in the constructor of the ActionListener, say an integer, and switch through these so:


//and inside the actionListener:

case 1:
   //do action for checkbox one
case 2:
   //dp action for checkbox two!

If you give it the same actionListener, that does the same action. Thats probably because you want the two check boxes to do the same thing...

thank you for your reply.
but getSource don't work.
and i want not in other class that i define the listener just i want in same class =>
thank you!

Then I guess you are out of luck.

Seriously, you haven't said why getSource() won't work (it will by the way) and you haven't given any good reason not to define separate listeners. You can define separate listeners as inner classes, anonymous or named.