简体   繁体   English

如何识别在当前选择的单选按钮之前选择了哪个单选按钮?

[英]How to recognise which radio button is selected before currently selected radio button?

I have two radio buttons, both added to a ButtonGroup . 我有两个单选按钮,都添加到ButtonGroup I have added an ActionListener for both. 我为两者都添加了一个ActionListener 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. 假设当前选择了第一个单选按钮,然后再次单击同一按钮,则再次调用actionPerformed() It doesn't look good. 看起来不太好。 I want to prevent the call to actionPerformed() if that radio button is already selected. 如果已选择该单选按钮,我想阻止对actionPerformed()的调用。

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. 一种可能的方法是将当前选定的单选按钮状态存储在变量中,但是我想知道用于此操作的java内部方法。

Is there any method to do this? 有什么方法可以做到这一点?

if(radioButton.isSelected()) this will tell you if its selected. if(radioButton.isSelected())会告诉您是否已选择。 if it's selected you don't perform action. 如果选择它,则不执行操作。 If it's not selected perform the action. 如果未选中,请执行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM