Method | Discription |
Slider(int x, int y, int width, int height, int min, int max, int orientation) | Creates a new Slider with given bounds. The parameters min and max specify the value range. The orientation is defined by using one of the two constant values ORIENTATION_HORIZONTAL and ORIENTATION_VERTICAL . |
setStep(int step) | Specifies the step size when the slider is moved. |
int getValue() | Returns the current value of the Slider . |
setValue(int value) | Changes the value of the Slider . If the new value exceeds the values margin (specified by the constructor), it will be adjusted. |
The following source code implements a small program example, which displays two Slider
s. Figure 3 shows a screenshot of this program. Like all examples in this tutorial, it comes with the JControl/IDE and is located in the installation directory under "demos/cobra5329/WombatTutorial/WombatSliderExample"
(on Windows "C:\Program Files\JControl\demos\cobra5329\WombatTutorial\WombatSliderExample"
).
1 | /** |
2 | * <p>This example demonstrates how to use the |
3 | * component Slider within |
4 | * the GUI framework JControl/Wombat.</p> |
5 | * |
6 | * <p>(C) DOMOLOGIC Home Automation GmbH 2007</p> |
7 | */ |
8 | import jcontrol.ui.wombat.Frame; |
9 | import jcontrol.ui.wombat.Container; |
10 | import jcontrol.ui.wombat.event.ActionListener; |
11 | import jcontrol.ui.wombat.Border; |
12 | import jcontrol.ui.wombat.Slider; |
13 | import jcontrol.ui.wombat.event.ActionEvent; |
14 | |
15 | public class WombatSliderExample extends Frame implements ActionListener { |
16 | |
17 | /** |
18 | * Constructor WombatSliderExample |
19 | */ |
20 | public WombatSliderExample() { |
21 | // create a container for the content of this frame |
22 | Container content = new Container(); |
23 | |
24 | // create borders and add them to the content |
25 | Border border = new Border("Slider", 70, 40, 180, 140, |
26 | Border.STYLE_SIMPLE_BORDER); |
27 | content.add(border); |
28 | |
29 | |
30 | /* create all Sliders |
31 | add them to the content |
32 | and define an actionlistener for each component */ |
33 | Slider horizontalSlider = new Slider(90, 57, 140, 18, 0, 100, |
34 | Slider.ORIENTATION_HORIZONTAL); |
35 | horizontalSlider.setEnabled(false); |
36 | content.add(horizontalSlider); |
37 | horizontalSlider.setActionListener(this); |
38 | Slider verticalSlider = new Slider(150, 80, 18, 90, 0, 100, |
39 | Slider.ORIENTATION_VERTICAL); |
40 | content.add(verticalSlider); |
41 | verticalSlider.setActionListener(this); |
42 | |
43 | // set the content to this frame |
44 | setContent(content); |
45 | // finally, make the frame visible |
46 | setVisible(true); |
47 | } |
48 | |
49 | /** |
50 | * This method is called every time any component declared above fires an |
51 | * action event. |
52 | * |
53 | * @param e the ActionEvent |
54 | */ |
55 | public void onActionEvent(ActionEvent e) { |
56 | // add some code if you want to |
57 | } |
58 | |
59 | |
60 | /** |
61 | * The main method. |
62 | * |
63 | * @param args |
64 | * The main arguments |
65 | */ |
66 | public static void main(String[] args) { |
67 | new WombatSliderExample(); |
68 | } |
69 | } |