CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades

Events

Events
Handle events
Structure event handling

Two steps to handle any event

  1. Create a class that implements the appropriate listener interface. In this class, you must code an implementation of the appropriate listener interface method to respond to the event.
  2. Register an instance of the listener class to the event source by calling the appropriate addeventListener method

Four options for implementing the listener interface

  • Implement it in the panel itself
  • Implement it in a separate class
  • Implement it in an inner class within the panel
  • Implement it in an anonymous inner class

Two options for handling multiple event sources

  • Create one listener that handles all events for the panel
  • Create a separate listener for each event
Previous | Java event model | Two types | Structure event handling | Panel | Separate class | Inner class | Separate event listeners | Anonymous inner classes | Next