As mentioned above, if you process Java events by overriding the convenience andhandleEvent
methods, you must understand how events are propagated. The two diagrams, below, will be used to discuss this issue.First, events are propagated up the class hierarchy, just like messages. (In fact, that is literally what is happening through calls to
handleEvent
.) If you overridehandleEvent
in, say, aPanel
subclass that you create, it will receive events that occur in it. Your method should then process the events it is interested in, but it should then pass events it is not interested in up the class hierarchy. This can be done by either areturn false
statement or by calling the superclass (e.g.,return super.handleEvent
). The second form is preferred forhandleEvent
.The same rule applies for convenience methods that you override. However, the preferred action for events not handled in your overrides is to
return false
rather thanreturn super.handleEvent
. Look at the class hierarchy and figure out why this is the preferred option.
![]()
Java AWT Class Hierarchy. Branch in which Panel
,Button
, andEvent
appear.Second, events are propagated within nested components. Thus, for example, if you nest a button within a panel within an applet, events will first be sent to the panel that encloses the button. If no
handleEvent
or convenience method processes the event there, it will be propagated to the applet.
![]()
Nested Component Hierarchy. Hierarchy of nested components used in examples, below. The somewhat tricky part is how these two hierarchies intertwine. The order is this: the lowest level component receives the event and attempts to process it either through a
return super.handleEvent
override or by allowing it to propagate up the class hierarchy. Since thehandleEvent
stub inComponent
returnsfalse
, the path leaves the class hierarchy for that component and moves on to the next level of enclosing object.If we think of the class path as extending vertically and the nesting path as horizontal, the process begins with the last item on the horizontal path, moves vertically up its class hierarchy, comes back down to the next to lowest horizontal item, moves up its vertical class hierarchy, then goes to the next horizontal item, etc.