import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JCheckbox_test  extends JFrame implements ActionListener {
    JCheckBox jCheckBox1 = new JCheckBox("张三");
    JCheckBox jCheckBox2 = new JCheckBox("李四");
    JCheckBox jCheckBox3 = new JCheckBox("王二");
    JTextField jText = new JTextField();
    JButton jButton = new JButton();
    public JCheckbox_test(){
        setLayout(null);
        jCheckBox1.setBounds(50, 20, 59, 25);
        jCheckBox2.setBounds(50, 50, 59, 26);
        jCheckBox3.setBounds(50, 80, 60, 20);
        jText.setBounds(120, 20, 80, 80);
        jButton.setBounds(80, 120, 80, 25);
        setTitle("复选框");
        jButton.setText("确定");
        jButton.addActionListener(this);
        add(jCheckBox1);
        add(jCheckBox2);
        add(jCheckBox3);
        add(jText);
        add(jButton);
    }
    public static void main(String args[]) {
        JCheckbox_test ta = new JCheckbox_test();
        ta.setBounds(200, 300, 250, 200);
        ta.validate();
        ta.setVisible(true);
    }
    public void actionPerformed(ActionEvent e) {
        String text="";
        if(jCheckBox1.isSelected()) text+=jCheckBox1.getText();
        if(jCheckBox2.isSelected()) text+=jCheckBox2.getText();
        if(jCheckBox3.isSelected()) text+=jCheckBox3.getText();
        jText.setText(text);
   }
}

