The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.awt.event  [8 examples]

e643. Handling Events with an Anonymous Class

If an event handler is specific to a component (that is, not shared by other components), there is no need to declare a class to handle the event. The event handler can be implemented using an anonymous inner class. This example demonstrates an anonymous inner class to handle key events for a component.
    
component.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent evt) {
        }
    });

 Related Examples
e644. Handling Action Events
e645. Handling Key Presses
e646. Handling Mouse Clicks
e647. Handling Mouse Motion
e648. Detecting Double and Triple Clicks
e649. Handling Focus Changes
e650. Firing Item Events


© 2002 Addison-Wesley.