Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unable to pick selected radiobutton

843806Aug 21 2007 — edited Aug 21 2007
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 18 2007
Added on Aug 21 2007
4 comments
24 views