Previous Page |Next Page
- So, as we said before, you also have another way which you can handle events. This is the Java 1.1 methodology.
- The JDK 1.1 model provides two related options for event handling: listeners and adapters. In the first case, you can use listener interfaces to catch events by creating a class that listens for events from other classes. To use listeners, a listenerobject implements a listener interface and tells the object it wants to listen to that that object should send event information.
- For example, to determine when an OK button is pressed, you first create a class that implements an action listener interface. Next, you create an object of that class type. Finally, you add that object as a listener to the OK button's list of listeners.
- You can also use adapter classes in conjunction with listeners in the JDK 1.1 event model. To catch events that use adapters, you create a separate class and an object of that class to listen for events. This class is designed to call methods on another object when events occur. So, when using adapters, an intermediate object is used to catch events and pass them on to some other object.
- Let's take a more detailed look at both listers and adapters.