What is the difference between hierarchical and delegate event handling in AWT?

RamaChandra Murthy

The hierarchical event handling in AWT specifies that the component interested in specific type of events has to handle events explicitly by the component i.e.,

  1. By subclassing the component
  2. By enabling the events in which the component is interested ini.e., by invoking enableEvents(long XXXevent)
  3. 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.

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact