我在数据库中有记录,我在jcheckbox中添加了我的程序,但我的问题是我不确定如何将itemListener添加到那些jcheckbox。我创建了一个jcheckbox数组。我想要做的是,一旦选中该复选框,其他人将被禁用。所以我将需要这个itemStateChanged事件。
请任何帮助。
public void my_form(){
JCheckBox jcb = new JCheckBox [number];
int counter = 0;
PreparedStatement pst1;
ResultSet rest1;
try{
pst1 = con.prepareStatement("select * from my_info");
rest1 = pst1.executeQuery();
while(rest1.next()){
String nameLast = rest1.getString("cand_nameLast");
String nameFirst = rest1.getString("cand_nameFirst");
jcb[counter] = new JCheckBox(nameLast +", "+ nameFirst);
//here i guess itemListener should be added. I'm not really sure
//how it should be.
jPanel6.add(jcb[counter]);
jPanel6.revalidate();
jPanel6.repaint();
counter ++;
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, e.getMessage());
}
}