Common Action Listener for 3 Buttons

前端 未结 2 830

I am having trouble with the design of my code. I have 3 buttons not in a button group. I want to - based on the selected button - perform an action. Now the action requires

2条回答
  •  不要未来只要你来
    2021-01-13 14:36

    You can set the same listener to all your buttons.

    Pseudo code:

    radioButton1 = new RadioButton();
    radioButton2 = new RadioButton();
    radioButton3 = new RadioButton();
    
    listener = new ActionListener() {
    ...
    }
    
    
    radioButton1.addActionListener(listener);
    radioButton2.addActionListener(listener);
    radioButton3.addActionListener(listener);
    

提交回复
热议问题