Java Reference
In-Depth Information
A slider produces a change event , indicating that the position of the slider and
the value it represents has changed. The ChangeListener interface contains a
single method called stateChanged . In the SlideColor program, the same listener
object is used for all three sliders. In the stateChanged method, which is called
whenever any of the sliders is adjusted, the value of each slider is obtained, the
labels of all three are updated, and the background color of the display panel is
revised. It is actually only necessary to update one of the labels (the one whose
corresponding slider changed). However, the effort to determine which slider was
adjusted is not warranted. It's easier—and probably more efficient—to update all
three labels each time. Another alternative is to have a unique listener for each
slider, though that extra coding effort is not needed either.
A slider is often a good choice when a large range of values is possible but
strictly bounded on both ends. Compared to alternatives such as a text field, slid-
ers convey more information to the user and eliminate input errors.
 
Search WWH ::




Custom Search