中国Java开发网 中国Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» 中国Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 JCheckBox array 问题
落叶无神





发贴: 2
积分: 0
于 2010-10-28 10:09 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
假设在我设了十个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,但是我没法做到。请诸位指教!




话题树型展开
人气 标题 作者 字数 发贴时间
16985 JCheckBox array 问题 落叶无神 2020 2010-10-28 10:09

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

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