0

hello!
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.

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Ezzaral
0

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:

checkboxOne.addActionListener(1);
checkboxOne.addActionListener(2);

//and inside the actionListener:

switch(thatThingICalledItInTheConstructor)
{
case 1:
   //do action for checkbox one
   break;
case 2:
   //dp action for checkbox two!
   break;
}

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...

Edited by hanvyj: n/a

0

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 =>
addItemListener(this);
thank you!

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.