Java Reference
In-Depth Information
methods of its own, but it inherits the getSource method from its superclass
EventObject . The getSource method tells us which component generated this
event, but we don't need that informationȌwe know that the event came from the
slider.
Now we have a plan: Add a change event listener to each slider. When the slider is
changed, the stateChanged method is called. Find out the new value of the slider.
Recompute the color value and repaint the color panel. That way, the color panel is
continually repainted as the user moves one of the sliders.
To compute the color value, you will still need to get the current value of the slider.
Look at all the methods that start with get . Sure enough, you find
public int getValue ()
Returns the slider's value.
Now you know everything you need to write the program. The program uses one new
Swing component and one event listener of a new type. Of course, now that you have
Ȓtasted bloodȓ, you may want to add those tick marksȌsee Exercise P18.10.
Figure 13 shows how the components are arranged in the frame. Figure 14 shows the
UML diagram.
Figure 13
The Components of the ColorViewerFrame
811
Search WWH ::




Custom Search