Topic: JCheckBox array 问题

  Print this page

1.JCheckBox array 问题 Copy to clipboard
Posted by: 落叶无神
Posted on: 2010-10-28 10:09

假设在我设了十个JCheckBox,我该怎样才能这些checkbox的index
public CheckBoxJFrame() {
super("Check Box");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600, 500);
JPanel selectarea = new JPanel();
selectarea.setMaximumSize(new Dimension(500, 300));
selectarea.setPreferredSize(new Dimension(500, 300));
//selectarea.setBorder(BorderFactory.createLoweredBevelBorder());
selectarea.setLayout(new GridLayout(7, 7, 5, 5));

num = new JCheckBox[50];
for (index = 1; index < num.length; index++) {
num[index] = new JCheckBox("" + index);
selectarea.add(num[index]);
num[index].addItemListener((ItemListener) this);
}
//button area
JPanel butarea = new JPanel();
butarea.setLayout(new FlowLayout());
butarea.setMaximumSize(new Dimension(500, 100));
butarea.setPreferredSize(new Dimension(500, 100));

butsubmit = new JButton("Submit");
butcheck = new JButton("Check");
txtwinnum = new JTextField(10);
butarea.add(butsubmit);
butarea.add(butcheck);
butarea.add(txtwinnum);

JPanel container = new JPanel();
container.setLayout(new FlowLayout());
container.add(selectarea);
container.add(butarea);
add(container);
setVisible(true);

}

public void itemStateChanged(ItemEvent e) {
int count = 0;
int n,Index = 1;
for (n = 1; n < num.length; n++) {
if (e.getStateChange() == ItemEvent.SELECTED) {

}
if(count > 5)
break;
}
txtwinnum.setText(txtwinnum.getText() + "," + );
// num[n].stSelected(true);

}

在上面的code中,如果checkbox的isselected的数量超过六,那最后的checkbox
必须被deselected,但是我没法做到。请诸位指教!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2018 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号
客服电话 0592-8750026    客服信箱 714923@qq.com    客服QQ 714923