Event Classes and Listener Interfaces

Event Classes and Listener Interfaces Java Swing uses event classes to encapsulate details about events and listener interfaces to respond to those events. This is the basis of Swing’s event delegation model. Event Classes Event classes are found in java.awt.event and javax.swing.event packages. Each class corresponds to a type of user action. Event Class Description ActionEvent Generated by buttons, menus, etc. MouseEvent Mouse actions like click, press KeyEvent Keyboard input WindowEvent Window state changes ItemEvent Checkbox, radio button changes public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); } Listener Interfaces Each event class has a corresponding listener interface. ...

May 8, 2025 · 1 min · Rohan