2015-04-06 31 views
0

所以我在我的if语句中的参数必须检查我的JRadioButton是否被选中,但是由于某种原因,即使它没有被选中,程序仍然运行。如何知道在java中是否启用了JRadioButton

public void actionPerformed(ActionEvent e) { 

    String actionCheck = Binary.userInput1.getText(); 

    if(Binary.binary.isEnabled() && actionCheck.matches("[01]+")){ // checks if its binary 
     int decimalValue = Integer.parseInt(actionCheck, 2); 
     String convertedDecimal = Integer.toString(decimalValue); 
     Binary.userInput2.setText(convertedDecimal); 
    } 

    else if (Binary.decimal.isEnabled() && decimalCheck(Binary.userInput1)){ 
     int binaryValue = Integer.parseInt(actionCheck); 
     Binary.userInput2.setText(Integer.toBinaryString(binaryValue)); 
    } 
    else 
     Binary.userInput1.setText("WRONG INPUT! -- try again"); 


} 

我在想什么?

按钮被称为二进制和十进制(是的,我知道,我的课被称为二进制代码,新手错误)

+1

'是的,我知道,我的班级也称为二进制,新手错误)' - 所以改变它。所有编辑都具有“更改全部”功能。 – camickr

回答

1

答案被发现!

这不是isEnabled()应该在这种情况下,但该方法​​

0

尝试来使用yourJRadioButton.isSelected()而不是isEnabled()

相关问题