Search code examples
javaswingjradiobutton

How to know if JRadioButton is enabled in java


So my argument in my if statement below has to check if my JRadioButton is checked, but for some reason, even if it's not checked, the program still runs.

    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");


}

What am I missing?

The buttons are called binary and decimal (Yes i know, my class is called Binary also, newbie errors)


Solution

  • Answer was found!

    It's not isEnabled() that should be used in this case but the method isSelected()