Java Reference
In-Depth Information
cg
=
0xFF;
cb
=
0xFF;
}
fOutputPanel.setColor (cr,cg,cb);
} // valueChanged
} // class ListPanel
Note the use of the
JScrollPane
class, which provides scroll bars (vertical
and horizontal) for those components, such as
JList
and
JTextArea
, that
implement the
Scrollable
interface. The bars appear whenever the content
extends beyond the visible area of the component.
7.3.4
JSlider
Sliders allow the user to choose from a continuous range of values rather than from
discrete values as with a set of buttons or a list. In Figure 7.7,
UiTestApplet
has selected
SliderPanel
as its control panel. The panel holds three instances
of
JSlider
. The user can move the sliders to select the values for the Red-
Green-Blue component values, each on a 0 to 255 scale. The combination of
these three color values becomes the background color of the
OutputPanel
.
Because of the continuous color changes possible, this is an applet that really
should be experienced live. To see the sliders in action, we encourage you either
to see the program on the Web Course site or to create the program from this
source code and run it on your own.
The constructor parameters set the orientation of the slider (horizontal or
vertical) and the upper and lower limit values. The last parameter sets the initial
value of the slider.
A slider sends instances of
ChangeEvent
to each of the entries added to its
ChangeListener
list. The panel therefore implements the
ChangeListener
interface and provides a
stateChanged()
method. The current value setting
on the slider is obtained easily with its
getValue()
method.
Figure 7.7
The
JSlider
component allows the user to select from a continuous
range of values. With the
SliderPanel
class displayed in
UITestApplet
, the three
sliders set the Red-Green-Blue component values from 0 to 255 each. The combined
RGB values determine the color of the background of the top area.
Search WWH ::
Custom Search