-
Notifications
You must be signed in to change notification settings - Fork 2
/
HMeterDemo.java
81 lines (64 loc) · 2.31 KB
/
HMeterDemo.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package Hasnat;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
public class HMeterDemo extends JFrame {
private HMeter meter1, meter2, meter3;
private JProgressBar progressBar;
private JSlider slider;
public HMeterDemo() {
meter1 = new HMeter(50, "HMeter 1");
meter1.setPadding(20);
meter1.setRadius(150);
meter1.setMaximumValue(200);
meter1.setProgressColor(Color.BLUE);
meter1.setTextColor(Color.WHITE);
meter1.setBoundaryColor(Color.GRAY);
meter2 = new HMeter(75, "HMeter 2");
meter2.setPadding(20);
meter2.setRadius(150);
meter2.setMaximumValue(300);
meter2.setProgressColor(Color.GREEN);
meter2.setTextColor(Color.WHITE);
meter2.setBoundaryColor(Color.GRAY);
meter3 = new HMeter(25, "HMeter 3");
meter3.setPadding(20);
meter3.setRadius(150);
meter3.setMaximumValue(500);
meter3.setProgressColor(Color.RED);
meter3.setTextColor(Color.WHITE);
meter3.setBoundaryColor(Color.GRAY);
progressBar = new JProgressBar(0, 100);
progressBar.setValue(50);
slider = new JSlider(0, 100, 50);
slider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
int value = slider.getValue();
meter1.setProgress(value*2);
meter2.setProgress(value*3);
meter3.setProgress(value*5);
progressBar.setValue(value);
}
});
JPanel panel = new JPanel(null);
meter1.setBounds(50, 50, 200, 200);
meter2.setBounds(300, 50, 200, 200);
meter3.setBounds(550, 50, 200, 200);
progressBar.setBounds(50, 300, 600, 30);
slider.setBounds(50, 350, 600, 30);
panel.add(meter1);
panel.add(meter2);
panel.add(meter3);
panel.add(progressBar);
panel.add(slider);
add(panel);
setSize(800, 450);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new HMeterDemo();
}
}