-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path09a_slider.java
64 lines (49 loc) · 1.65 KB
/
09a_slider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import javax.swing.*;
import java.awt.event.*;
public class GUIApp {
public static void main(String[] args) {
// https://docs.oracle.com/javase/7/docs/api/javax/swing/JSlider.html
JFrame frame = new JFrame("Cupertinii Swing GUI");
frame.setSize(500, 500);
// I had to comment following line out to get the slider
// frame.setLayout(null);
horizontalSlider(frame);
verticalSlider(frame);
frame.setLayout(null);
frame.setVisible(true);
}
public static void horizontalSlider(JFrame frame) {
// JSlider mySlider = new JSlider(JSlider.HORIZONTAL);
int min = 0;
int max = 100;
int current_value = 20;
JSlider mySlider = new JSlider(JSlider.HORIZONTAL, min, max, current_value);
mySlider.setLocation(20, 20);
mySlider.setSize(200, 60);
mySlider.setFocusable(true);
mySlider.setSnapToTicks(true);
mySlider.setPaintTrack(true);
mySlider.setPaintTicks(true);
mySlider.setPaintLabels(true);
mySlider.setMinorTickSpacing(5);
mySlider.setMajorTickSpacing(25);
frame.add(mySlider);
}
public static void verticalSlider(JFrame frame) {
// JSlider mySlider = new JSlider(JSlider.HORIZONTAL);
int min = 0;
int max = 100;
int current_value = 20;
JSlider mySlider = new JSlider(JSlider.VERTICAL, min, max, current_value);
mySlider.setLocation(20, 100);
mySlider.setSize(60, 200);
mySlider.setFocusable(true);
mySlider.setSnapToTicks(true);
mySlider.setPaintTrack(true);
mySlider.setPaintTicks(true);
mySlider.setPaintLabels(true);
mySlider.setMinorTickSpacing(1);
mySlider.setMajorTickSpacing(10);
frame.add(mySlider);
}
}