Below are a few snippets of code to show you what I am trying to do, and
possibly what I am doing incorrectly. What I end up with is the last radio
button to be selected is the one that is used (for drawing). So if I select 1 then I draw with 1, if I select 2 then it draws with a 2, if I select 4 then it draws with a 4. But when I try to go back to 2 or 1 it draws with a 4(the last one selected). I assumed that it was because this was a listener for mulitple actions and that I am adding them in at the same time and that I am creating a new JRadioButtonMenuItem everytime I add something (Basically I have N action listeners, one for each item I create. I have tried to pass this in as a parameter only to get the same results. Can I do this or is there really
not an elegant design option here? Ultimately I want to pull all of my
listeners into a seperate class (Not Inner), but currently I am testing it in a method.
Thanks in advance.
[ April 30, 2007: Message edited by: Gabriel White ]
I usually have a rule of thumb that you only use an anonymous inner class when you have one and only one Listener doing a particular task. In your case, however, because you have a button-creating method, you could make an exception to that rule. Go back to your original plan
All you have to do is to add the method you commented out as part of an anonymous inner class. Like this:-Notice I have changed the parameter to int width. It is easier to write "" + width than the parseInt() method. And the bit about '0' + width will work nicely as long as width < 10. Even though you are now supposed to pass an int to the setMnemonic method.
//setThicknessButton() method (stuff moved to setupListeners commented out)
private JRadioButtonMenuItem setThicknessButton(String name, ButtonGroup
thicknessMenuItem = new JRadioButtonMenuItem(name, false);
public void actionPerformed(ActionEvent e)