Tutorial 3
Slider Control Variables
GOAL: To understand that control variables can be a pre-defined class and demonstrate working with control variables
PREREQUISITES: Tutorial 2
Add Text Fields
For Vertical Slider Bar
- Open the Palette
- Drag a JLabel to the JFrame
window
- and change the text property to "Vertical Bar"
- Create a JLabel with
- Change Variable Name... to "lbl_VSlider_Echo"
- text to "0"
- border to
- Drag a JSlider to the JFrame window,
and Change Variable Name... to "vSliderBar".
Next, inside the Properties window, change
- to
"VERTICAL"
- minimum to 0
- maximum to 100
- value to 0
Create
Event Handler For Vertical Slider Bar
- Select the main application window and Left-Mouse-Button
single click to select the vertical slider bar, then
Right-Mouse-Button single-click on it, and then select
Events >> Change >> stateChanged
- Now inside the function code block for
vSliderBarStateChanged(...), add the following code:
lbl_VSlider_Echo.setText(
Integer.toString( vSliderBar.getValue() ) );
Add Text Fields
For Horizontal Slider Bar
- Drag a JLabel to the JFrame
window
- and change the text property to "Horizontal Bar"
- Create a JLabel with
- Change Variable Name... to "lbl_HSlider_Echo"
- text to "0"
- border to
Add Horizontal Slider Bar,
and Event Handler
- Repeat the steps for Adding Vertical Slider Bar with the following changes
- Inside the Slider Control Properties window, change
- Change Variable Name... to "hSliderBar"
-
as "HORIZONTAL"
- Create an Event Handler,
and inside the function code block for it, add the following code:
lbl_HSlider_Echo.setText( Integer.toString(
hSliderBar.getValue() ) );
- In the project window, click
- >>
- Run >> to run
Figure 3.2 - Application Window
» Written by
William Frankhouser (
wjf2@washington.edu)
» Adapted by Michael Panitz.
» Advised by
Kelvin Sung (
ksung@washington.edu)
as part of the project sponsored by the National Science Foundation under Grant No. 0442420. Any opinions, findings, and conclusions or recommendations expressed in this
material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.
» Produced in the "Essential Concepts for Building Interactive Computer Graphics Applications", A.K. Peters, Ltd.