/Users/lyon/j4p/src/gui/run/RunCheckBox.java
|
1 package gui.run;
2
3 import gui.ClosableJFrame;
4
5 import javax.swing.*;
6 import java.awt.*;
7 import java.awt.event.ItemEvent;
8 import java.awt.event.ItemListener;
9
10
11 public abstract class RunCheckBox extends
12 JCheckBox
13 implements
14 ItemListener,
15 Runnable {
16 public RunCheckBox(String label) {
17 this(label, false);
18 addItemListener(this);
19 }
20
21 public RunCheckBox(Icon i, boolean b) {
22 super(i, b);
23 addItemListener(this);
24 }
25
26 public RunCheckBox(String s, boolean b) {
27 super(s, b);
28 addItemListener(this);
29 ShortcutUtils.addShortcut(this);
30 }
31
32 public RunCheckBox(Icon i) {
33 super(i);
34 addItemListener(this);
35 }
36
37 public RunCheckBox() {
38 addItemListener(this);
39 }
40
41 public void itemStateChanged(ItemEvent e) {
42 run();
43 }
44
45
46 public static void testRunCheckBox() {
47 ClosableJFrame cf = new ClosableJFrame("RunCheckBox");
48 Container c = cf.getContentPane();
49 c.add(new RunCheckBox("[RunCheckBox") {
50 public void run() {
51 System.out.println(getText() + "=" +
52 isSelected());
53 }
54 });
55 c.add(new RunCheckBox("[CheckMe, Baby!") {
56 public void run() {
57 System.out.println(getText() + "=" +
58 isSelected());
59 }
60 });
61 c.setLayout(new java.awt.GridLayout(4, 0));
62 cf.setSize(200, 200);
63 cf.setVisible(true);
64
65 }
66 }