I'm creating a JFrame with 3 buttons, 3 checkboxes, and 3 radio buttons. I'm having a problem with a function that is excecuted when 1 of the 3 buttons is pressed. This is the function:
private void setCenterColors() {
if(redB.isSelected()) {
center.setBackground(Color.RED);
} else if (greenB.isSelected()) {
center.setBackground(Color.GREEN);
} else if (blueB.isSelected()){
center.setBackground(Color.BLUE);
}
System.out.println(center.getBackground());
}
redB, greenB, and blueB are all JButtons.
The event handler for the buttons is:
class ChoiceListenerButton implements ActionListener {
public void actionPerformed(ActionEvent event)
{
setCenterColors();
repaint();
}
}
listenerButton = new ChoiceListenerButton();
When i excecute the program and press the buttons, all of them returns false, when one of them should return true. What should i do to see which button is pressed? Any help is appreciated, if you need full code, please ask and i will replay as soon as is see the notification. Thank you.