Forwarding

 

As indicated earlier, events are sent first to either the Component or to one is its subclasses, such as Button. What happens there is invisible if one or more objects have registered with the component. However, a quick look at the methods that provide forwarding is useful for gaining a general understanding of the process. Furthermore, programmers can elect to handle events within the component, itself, although this lower level option will not be discussed here.

The process is quite simple. When the JVM receives an event for a given object, it calls a processEvent method in that object. That methods looks at the type of event and, depending on the type, sends it to a more specialized method. For example, in Button, most events will be sent by the processEvent method to a processActionEvent method. If an object has registered with this button, the processActionEvent method dispatches the event to that object. How it does this will be discussed next.