I have a gui that has 10 buttongroup, each group having two radiobuttons (say like enable & disable) and one button. In gui i first select required radiobuttons and on click of button i should get all radiobuttons which are enabled or disabled. For this i have created two radiobutton arrays and one buttongroup array.
private JRadioButton[] enable;
private JRadioButton[] disable;
private ButtonGroup[] bg;
private int values[];
...
..
Somewhere in constructor i initialised these componenets (say array size is 10). And in my actionperformed.
public void actionPerformed(ActionEvent e) {
if(onclickofbutton) {
loop for 10 times //array size
if(getSelection(bg[index], index) == 1) {
put 1 in values array
}
else {
put 0 in values array
}
}
public int getSelection(ButtonGroup group, int index) {
int retVal = 0;
for (java.util.Enumeration e=group.getElements(); e.hasMoreElements(); ) {
JRadioButton b = (JRadioButton)e.nextElement();
if (b.getModel() == group.getSelection()) {
if(b == enable[index]) {
retVal = 0;
}else { //if(b == disable[index]){
retVal = 1;
}
// }
}
}
return retVal;
}
I dont know where i am wrong. I am not getting selected radiobuttons.