OnJava8-Examples/gui/CheckBoxes.java

33 lines
900 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: gui/CheckBoxes.java
// Using JCheckBoxes.
import javax.swing.*;
import java.awt.*;
import static net.mindview.util.SwingConsole.*;
public class CheckBoxes extends JFrame {
private JTextArea t = new JTextArea(6, 15);
private JCheckBox
cb1 = new JCheckBox("Check Box 1"),
cb2 = new JCheckBox("Check Box 2"),
cb3 = new JCheckBox("Check Box 3");
public CheckBoxes() {
2015-05-06 12:09:38 -07:00
cb1.addActionListener(e -> trace("1", cb1));
cb2.addActionListener(e -> trace("2", cb2));
cb3.addActionListener(e -> trace("3", cb3));
2015-04-20 15:36:01 -07:00
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");
else
t.append("Box " + b + " Cleared\n");
}
public static void main(String[] args) {
run(new CheckBoxes(), 200, 300);
}
} ///:~