Re: I am getting multiple events when clicking my radiobutton
marcussilfver@gmail.com wrote:
That is why I figured that my
problem arise from putting the creation & eventhanling of the
radiobuttons in the method that the model fires update invocations
at.
I read this three times, I couldn't parse this sentence.
My little test had two classes. One was the JFrame I used to test. The
other was pretty much just boilerplate Main class to start the app.
I add four MouseListeners, one for each button, in Main:
private void testIt()
{
for ( int i = 0; i < 4; i++ )
{
final int j = i+1;
rb.addButtonListener( i, new MouseAdapter()
{
@Override
public void mouseClicked( MouseEvent e )
{
System.out.println( "I was clicked: "+j );
}
});
}
}
(The JFrame object is stored in "rb" above.)
And in the JFrame class I just add the MouseListener to the requested
button:
public void addButtonListener( int which, MouseListener el )
{
JRadioButton r = buttons.get( which );
r.addMouseListener( el );
}
"buttons" is an ArrayList, not a Vector, but same idea.
I'd post the whole thing, but I made the JFrame in Matisse and it's a
bit verbose, and it sounds like you've duplicated this example anyway.
I'd put a breakpoint on your equivalent of the addButtonListener method
above and watch for any button getting more than one MouseListener.