-
Notifications
You must be signed in to change notification settings - Fork 0
/
Swing43.java
39 lines (34 loc) · 1.03 KB
/
Swing43.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
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
public class Swing43 extends JFrame {
public static void main(String[] args) { new Swing43();}
JSlider s;
JLabel label;
Swing43(){
setTitle("JSlider Program");
setSize(400,400);
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
s = new JSlider();
add(s);
s.setMinimum(0);
s.setMaximum(200);
s.setPaintTicks(true);
s.setPaintLabels(true);
s.setMajorTickSpacing(50);
s.setMinorTickSpacing(5);
s.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
label.setText("knob is at "+s.getValue());
}
});
label = new JLabel();
label.setText("knob is at "+s.getValue());
add(label);
setVisible(true);
validate();
}
}