java swing 复选框JCheckButton
效果图
代码:
import java.io.File ; import java.awt.GridLayout ; import java.awt.Container ; import java.awt.event.WindowAdapter ; import java.awt.event.WindowEvent ; import java.awt.event.WindowListener ; import java.awt.event.ItemListener ; import java.awt.event.ItemEvent ; import javax.swing.JFrame ; import javax.swing.JPanel ; import javax.swing.JCheckBox ; import javax.swing.BorderFactory ; import javax.swing.ButtonGroup ; import javax.swing.ImageIcon ; class MyCheck { private JFrame frame = new JFrame() ; Container con = frame.getContentPane() ; JPanel pan = new JPanel() ; JCheckBox jcb1 = new JCheckBox("在校生") ; JCheckBox jcb2 = new JCheckBox("男生") ; JCheckBox jcb3 = new JCheckBox("本科") ; public MyCheck() { pan.setBorder(BorderFactory.createTitledBorder("请选择")) ; pan.add(jcb1) ; pan.add(jcb2) ; pan.add(jcb3) ; con.add(pan) ; this.frame.setSize(300,200) ; this.frame.setVisible(true) ; this.frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(1) ; } }) ; } } class Tester { public static void main(String args[]) { new MyCheck() ; } }