Gaurav Sharma
Gaurav Sharma

Reputation: 25

How to recognise which radio button is selected before currently selected radio button?

I have two radio buttons, both added to a ButtonGroup. I have added an ActionListener for both. Suppose that at present the first radio button is selected, then again if I click on the same button then again actionPerformed() will be called. It doesn't look good. I want to prevent the call to actionPerformed() if that radio button is already selected.

One possible way could be to store current selected radio button state in a variable, but I want to know the java internal method for this.

Is there any method to do this?

Upvotes: 1

Views: 761

Answers (1)

XtremeBaumer
XtremeBaumer

Reputation: 6435

if(radioButton.isSelected()) this will tell you if its selected. if it's selected you don't perform action. If it's not selected perform the action.

Upvotes: 2

Related Questions