-1

I have a class called OpenSavedData which implements an action listener. I want to call a different action listener after the execution of above without clicking on the menu item.

1
  • 1
    Posting some code would help, Also what have you tried?
    – Java Devil
    Aug 21, 2013 at 21:28

1 Answer 1

2

Delegate to a common method:

private void doSomething() {
    // ...
}

// 1st action listener:
myMenuItem.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        doSomething();
    }
});

// 2nd action listener:
myButton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        // ...
        doSomething();
    }
});
2
  • I think from the OP's description myButton should doSomethingElse() while myMenuItem should doSomething() then doSomethingElse(). Aug 21, 2013 at 21:53
  • 1
    agreed, this is about 1. Swing Action, 2. EventHandler. 3. redistribute ActionEvent e as something against earth gravity, 4. doClick()
    – mKorbel
    Aug 21, 2013 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.