Java ActionListener InterfaceThe Java ActionListener is notified whenever you click on the button or menu item. It is notified against ActionEvent. The ActionListener interface is found in java.awt.event package. It has only one method: actionPerformed(). actionPerformed() methodThe actionPerformed() method is invoked automatically whenever you click on the registered component. How to write ActionListenerThe common approach is to implement the ActionListener. If you implement the ActionListener class, you need to follow 3 steps: 1) Implement the ActionListener interface in the class: 2) Register the component with the Listener: 3) Override the actionPerformed() method: Java ActionListener Example: On Button clickOutput: Java ActionListener Example: Using Anonymous classWe can also use the anonymous class to implement the ActionListener. It is the shorthand way, so you do not need to follow the 3 steps: Let us see the full code of ActionListener using anonymous class. Output: Next TopicJava MouseListener |