import javax.swing.*; import java.awt.FlowLayout; import java.awt.event.*; public class Exec61 extends JFrame implements ActionListener{ JTextField text; JCheckBox jc1,jc2,jc3; Exec61(){ setTitle("Test"); setSize(400,500); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(new FlowLayout()); jc1 = new JCheckBox("足球"); ButtonGroup g = new ButtonGroup(); jc2 = new JCheckBox("篮球"); jc3 = new JCheckBox("排球"); jc1.addActionListener(this); jc2.addActionListener(this); jc3.addActionListener(this); g.add(jc1); g.add(jc2); g.add(jc3); text = new JTextField(10); add(jc1); add(jc2); add(jc3); add(text); pack(); setVisible(true); } @Override public void actionPerformed(ActionEvent e) { JCheckBox jc = (JCheckBox)(e.getSource()); text.setText(jc.getActionCommand()); } public static void main(String[] args) { new Exec61(); } }