addActionListener
addActionListener is a method used in Java's AWT and Swing to register listeners that respond to action events. It is defined by components such as Button and AbstractButton (including JButton) as well as JMenuItem, and it accepts an ActionListener. The ActionListener interface declares one method, actionPerformed(ActionEvent e), which is invoked when the user activates the component (for example, by clicking a button or selecting a menu item) or when an action event is fired programmatically.
Typical usage involves providing an ActionListener implementation and adding it to the component: button.addActionListener(new ActionListener() { public
Multiple listeners can be attached to a single component; they are notified in the order they were
Events generated by addActionListener are dispatched on the Event Dispatch Thread. Long-running tasks inside actionPerformed should
This mechanism embodies the observer pattern, allowing modular handling of user interactions. It is widely used