2015-04-06 98 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()

相關問題