What is the difference between hierarchical and delegate event handling in AWT?
- By subclassing the component
- By enabling the events in which the component is interested ini.e., by invoking enableEvents(long XXXevent)
- By overriding the public void processXXXEvent(XXXEvent event) method.
This way of subclassing each component and enabling the events which the componet has to handle is a tedious and cumbersome process.Hence,generally the delegation model is preferred.
The delegation model specifies that each component can delegate the job of event handling to objects called Listeners which must register with the event source.. Whenever an event is fired from a component, an event object is propagated to an appropriate method in the Listener object, and that method contains code to handle the event. Corresponding to every AWTEvent there is a corresponding event listener. For example, for ActionEvent we have ActionListener.