Hi.
I need to save an "1" and "0" array to a plain file taking these values from an "CheckBox" array, but i have problems when i wanted to check if a check box is or not "selected" while processing a ItemStateChange listener, the CheckBox checked is done depending on this "1" or "0" array, look the code:
public class XXX extends JFrame{
private JCheckBox op[];
...
public XXX(String[] cad, StringBuffer ops){
op = new JCheckBox[cad.length];
CheckBoxHandler chkChg = new CheckBoxHandler();
for (int ind=0;ind<cad.length;ind++){
op[ind] = new JCheckBox(cad[ind]);
if (ops.charAt(ind)=='1')
op[ind].setSelected(true);
nvoOps.add(op[ind]);
op[ind].addItemListener(chkChg); // is this Ok?
}
...
public class CheckBoxHandler implements ItemListener {
private int no;
private String el;
public void itemStateChanged(ItemEvent e){
no = e.getStateChange();
if (no==1){
el=e.getSource().toString();
JOptionPane.showMessageDialog(null,"Selected " + el);
} else {
el=e.getSource().toString();
JOptionPane.showMessageDialog(null,"Unselected " + el);
}
}
}
But when i tried to change the value of StringBuffer ops i can't catch the op[ind] object as source, can anyone know how can i do this? help will be appreciate.
thanks
Mac2K
I need to save an "1" and "0" array to a plain file taking these values from an "CheckBox" array, but i have problems when i wanted to check if a check box is or not "selected" while processing a ItemStateChange listener, the CheckBox checked is done depending on this "1" or "0" array, look the code:
public class XXX extends JFrame{
private JCheckBox op[];
...
public XXX(String[] cad, StringBuffer ops){
op = new JCheckBox[cad.length];
CheckBoxHandler chkChg = new CheckBoxHandler();
for (int ind=0;ind<cad.length;ind++){
op[ind] = new JCheckBox(cad[ind]);
if (ops.charAt(ind)=='1')
op[ind].setSelected(true);
nvoOps.add(op[ind]);
op[ind].addItemListener(chkChg); // is this Ok?
}
...
public class CheckBoxHandler implements ItemListener {
private int no;
private String el;
public void itemStateChanged(ItemEvent e){
no = e.getStateChange();
if (no==1){
el=e.getSource().toString();
JOptionPane.showMessageDialog(null,"Selected " + el);
} else {
el=e.getSource().toString();
JOptionPane.showMessageDialog(null,"Unselected " + el);
}
}
}
But when i tried to change the value of StringBuffer ops i can't catch the op[ind] object as source, can anyone know how can i do this? help will be appreciate.
thanks
Mac2K