-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCBDemo.java
More file actions
77 lines (58 loc) · 1.96 KB
/
Copy pathCBDemo.java
File metadata and controls
77 lines (58 loc) · 1.96 KB
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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class CBDemo implements ItemListener {
JLabel jlabSelected;
JLabel jlabChanged;
JCheckBox jcbAlpha;
JCheckBox jcbBeta;
JCheckBox jcbGamma;
CBDemo() {
JFrame jfrm = new JFrame("Demonstrate Check Boxes");
jfrm.setLayout(new FlowLayout());
jfrm.setSize(280, 120);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jlabSelected = new JLabel("");
jlabChanged = new JLabel("");
jcbAlpha = new JCheckBox("Alpha");
jcbBeta = new JCheckBox("Beta");
jcbGamma = new JCheckBox("Gamma");
jcbAlpha.addItemListener(this);
jcbBeta.addItemListener(this);
jcbGamma.addItemListener(this);
jfrm.add(jcbAlpha);
jfrm.add(jcbBeta);
jfrm.add(jcbGamma);
jfrm.add(jlabChanged);
jfrm.add(jlabSelected);
jfrm.setVisible(true);
}
public void itemStateChanged(ItemEvent ie) {
String str = "";
JCheckBox cb = (JCheckBox) ie.getItem();
if(cb.isSelected())
jlabChanged.setText(cb.getText() + " was just selected.");
else
jlabChanged.setText(cb.getText() + " was just cleared.");
if(jcbAlpha.isSelected()) {
str += "Alpha ";
}
if(jcbBeta.isSelected()) {
str += "Beta ";
}
if(jcbGamma.isSelected()) {
str += "Gamma";
}
jlabSelected.setText("Selected check boxes: " + str);
}
public static void main(String args[]) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {};
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new CBDemo();
}
});
}
}