Setting label in Java button listener How can I avoid so many if statements?

//Radio Button toggle


if (five.isSelected() == true) {
            one.setSelected(false);

    private class JButtonListner implements ActionListener {

//As my code has 4 options (1,5,+,-) to change the label, i have done 4 if else statments. is it possible to avoid such mess?


        public void actionPerformed(ActionEvent e) {
            if (e.getSource().equals(plus) &amp;&amp; five.isSelected() == true) {
                count += 5;
                label.setText(Integer.toString(count));

            } else if (e.getSource().equals(minus) &amp;&amp; five.isSelected() == true) {
                count -= 5;
                label.setText(Integer.toString(count));

            } else if (e.getSource().equals(minus) &amp;&amp; one.isSelected() == true) {
                count --;
                label.setText(Integer.toString(count));

            } else if (e.getSource().equals(plus) &amp;&amp; one.isSelected() == true) {
                count++;
                label.setText(Integer.toString(count));
            }
        }
It would be nice to see more of the code since one, five, plus and minus give NullPointerException

public void actionPerformed(ActionEvent event) {
      int value = five.isSelected() ? 5 : 1;
      if (event.getSource().equals(plus)) {
                count += value;      
      } else if (event.getSource().equals(minus)) {
                count -= value;
      } 
      label.setText(Integer.toString(count));
}


Since you only have 2 RadioButton, that would mean that the value could only be two values, either 5 or 1. This can be done by line two, you are asking if five.isSelected(), if(five.isSelected()) { return 5; } else { return 1; }. Also there is no need to say five.isSelected() == true, because the if already asks if it is true so five.isSelected() is sufficient.

Now you dont need to plus/minus with 5 or 1, but only check plus or minus.

And you set the text each time count has changed, so this can just be done after the if.