0

I need to use two JRadioButtons (already set up the ButtonGroup) to determine which of two Objects will be worked with.

savingsButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            AbstractButton aButton = (AbstractButton) e.getSource();
            if (aButton == savingsButton) {
                //set the target Object to savingsAccount
            }
        } 
    });

The other ActionListener is identical, save for swapping checkingAccount for savingsAccount.

How can I accomplish this?

dpooley
  • 1
  • 1
  • 2
    I'm not entirely sure what you're trying to achieve, but you can also use JRadioButton#isSelected to test if one or the other of the buttons is selected, assuming they are in the same ButtonGroup – MadProgrammer Jun 11 '15 at 23:13
  • 1
    Why not just have `e.getActionCommand()` and add a command (a string) to each object that can fire the listener? It will be much easier like that. – Zizouz212 Jun 12 '15 at 00:13
  • 1
    Since you're adding an action listener explicitly to savingsButton, you could just go ahead and do the same thing for checking button and set the target object as needed. No need to check the source of the action if you're using two different action listeners. – swingMan Jun 12 '15 at 00:30

0 Answers0