Java Reference
In-Depth Information
LISTING 10.14
continued
DISPLAY
10.10 Sliders
A slider is a component that allows the user to specify a
numeric value within a bounded range. A slider can be pre-
sented either vertically or horizontally and can have optional
tick marks and labels indicating the range of values.
A program called SlideColor is shown in Listing 10.15.
In one sense, this program is an improvement over the
DisplayColor program from the previous section in that it allows the user to con-
stantly change the displayed color without using a color chooser each time. This
program presents three sliders that control the RGB components of a color. The
color specified by the values of the sliders is shown in a square that is displayed
to the right of the sliders.
The SlideColorPanel class shown in Listing 10.16 is a panel used to display
the three sliders. Each is created from the JSlider class, which accepts four
parameters. The first determines the orientation of the slider using one of two
JSlider constants ( HORIZONTAL or VERTICAL ). The second and third parameters
specify the maximum and minimum values of the slider, which are set to 0 and
255 for each of the sliders in the example. The last parameter of the JSlider
KEY CONCEPT
A slider lets the user specify a
numeric value within a bounded
range.
 
Search WWH ::




Custom Search