Chain of Responsibility (5.1)

The Event Delegation Model of Java 1.0 adopts the Chain of Responsibility pattern to dispatch events to event handlers. Design, code and test an applet base on Java 1.0 which contains two Buttons and a TextField. Label "On" and "Off" the buttons. When button "On" is pressed, output the string "Pressed On button", and likewise for the "Off" button. You can accomplish this easily by overriding the action method of class Button. Test this version of your applet.

Now, augment the functionality of your applet. When button "On" is pressed, set the text of the TextField to "The On button has been pressed", and likewise for the "Off" button. You can achieve this result either by making the button aware of the TextField or by giving the responsibility to the applet. Discuss pros and cons of each choice. The Event Delegation Model of Java 1.0 makes the chaining responsabilities an easy and natural choice.