package Gui; /** * check box must be in a same ButtonGroup can`t be selected * at the same time * * */ import javax.swing.*; import java.awt.*; public class CheckBoxDemo extends JFrame{ public void launch(){ ButtonGroup bp = new ButtonGroup(); JCheckBox[] cb = new JCheckBox[10]; for(int i = 0 ;i<10;i++){ cb[i] = new JCheckBox("cb"+i); bp.add(cb[i]); add(cb[i]); } setLayout(new FlowLayout()); setBounds(600,200,300,300); setVisible(true); } public static void main(String[] args) { CheckBoxDemo bbb = new CheckBoxDemo(); bbb.launch(); } }
single checkbox demo
时间: 2024-12-17 01:25:35