2015-09-07 11:44:36 -06:00
|
|
|
// ui/CheckBoxes.java
|
2015-12-15 11:47:04 -08:00
|
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
2015-11-15 15:51:35 -08:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
2015-06-15 17:47:35 -07:00
|
|
|
// Using JCheckBoxes.
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
2015-11-11 20:20:04 -08:00
|
|
|
import static onjava.SwingConsole.*;
|
2015-06-15 17:47:35 -07:00
|
|
|
|
|
|
|
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() {
|
|
|
|
cb1.addActionListener(e -> trace("1", cb1));
|
|
|
|
cb2.addActionListener(e -> trace("2", cb2));
|
|
|
|
cb3.addActionListener(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");
|
|
|
|
else
|
|
|
|
t.append("Box " + b + " Cleared\n");
|
|
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
|
|
run(new CheckBoxes(), 200, 300);
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
}
|