-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCheckBoxes.java
More file actions
64 lines (52 loc) · 1.55 KB
/
CheckBoxes.java
File metadata and controls
64 lines (52 loc) · 1.55 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
package gui;
/**
* RUN:
* javac -cp .; gui/CheckBoxes.java && java -cp .; gui.CheckBoxes
* OUTPUT:
*
*/
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import net.mindview.util.*;
public class CheckBoxes extends JFrame {
private static final int WIDTH = 200;
private static final int HEIHGT = 300;
private JTextArea t = new JTextArea(6, 15);
private JCheckBox cb1 = new JCheckBox("Check Box 1");
private JCheckBox cb2 = new JCheckBox("Check Box 2");
private JCheckBox cb3 = new JCheckBox("Check Box 3");
public CheckBoxes() {
cb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
trace("1", cb1);
}
});
cb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
trace("2", cb2);
}
});
cb3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
trace("3", cb3);
}
});
setLayout(new FlowLayout());
add(new JScrollPane(t));
add(cb1);
add(cb2);
add(cb3);
}
private void trace(String b, JCheckBox cb) {
if (cb.isSelected()) {
t.append("Box " + b + " Set\n");
return;
}
t.append("Box " + b + " Cleared\n");
}
public static void main(String[] args) {
SwingConsole.run(new CheckBoxes(), WIDTH, HEIHGT);
}
}