Let’s say I have a JMenuItem with a text inside “Exit”, and a JButton with the text “Exit”,
the command which JButton will use is System.exit(0), of course using Action Listener, Ok i Know, I can put the same codes when clicking on the JMenuItem, but isn’t there a way, that when I click on the JMenuItem, the JButton is clicked so then the following commands are executed (JButton commands)?
Let’s say I have a JMenuItem with a text inside Exit, and a JButton
Share
What you can do is create an
Actionobject, and use that for both yourJButtonand yourJMenuItem.