FIGURE 3.60
The ControlComponent Class Description
/** * service() is none for none to visually highlight a selected button * and restore appearance of the last pressed button * @param newsParameters of the currently pressed button */ public Hashtable service(Hashtable newsParameters) { // a name of a button is a single key of the Hashtable Enumeration keys = newsParameters.keys(); String name = (String)keys.nextElement(); // change control button appearance to highlight a selected button if(buttonPressed != null) { buttonPressed.

setForeground(selectedForeground); buttonPressed.setBackground(selectedBackground); } return newsParameters; }. FIGURE 3.61
The namesAndLetter none for none s Hashtable is used to create a set of control buttons. While creating the buttons, we put every button into the namesAndButtons Hashtable, placing a button name as the key for the button object. The build() method looks for the namesAndLetters Hashtable in the build section of the con guration le that points to the ControlComponent.

If there are no speci c instructions there, the build() method gets this XML element from the general container description (this is the case in our example). Figure 3.61 contains the service() method.

The service() method of the ControlComponent visually highlights a selected button and restores the appearance of the button that was last pressed. The last fragment of the ControlComponent class is the getEventSources(), displayed in Fig. 3.

62. The getEventSources() method checks to determine whether the con guration le includes event-hander instructions for the ControlComponent. If so, the method creates a Hashtable of parameters and lls it with con guration instructions.

Then the method places all the control buttons (one by one) into the Hashtable, providing a unique key for each button. The key name consists of the Button string followed by the name of a button. This gives the container a hint that the source of events is java.

awt.Button. The getEventSources() method returns null if the con guration le has no instructions for event handling for the component.

FIGURE 3.62
REUSE, NOT ABUSE
Can reuse become u nnecessary overhead Yes, it does happen. Some developers (especially beginners) tend to create every new class or method using an existing library. This tendency can easily become abusive.

Imagine that you buy a cup. The cup appears to be a great t for the cup holder in your car. You use this cup in your car most of the time, so it becomes your car cup.

Then your current project makes you stay long hours at the of ce, and you feel the need for coffee more and more. A beginner would tend to reuse her or his car cup, even if it is not very convenient. Experienced developers can evaluate the situation and usually make a better decision: in this case, buying a second cup.