File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Regarding RadioButton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Regarding RadioButton" Watch "Regarding RadioButton" New topic
Author

Regarding RadioButton

tadi raja
Ranch Hand

Joined: Jul 07, 2008
Posts: 109
I am developing a GUI application,in that there are 5 radio buttons ysite,admixture,solution,syringe,TPN and ALL in which when i was selected any radio button and enter some textfields and press the enter button it can call corresponding web services methods,Here i implemented the code.

Here is the sample code for radio button

ysite = new StandardRadioButton("Y-Site");
admixture = new StandardRadioButton("Admixture");
solution = new StandardRadioButton("Solution");
syringe = new StandardRadioButton("Syringe");
TPN = new StandardRadioButton("TPN");
all = new StandardRadioButton("All");

String[] admin = {"YSITE","ADMIXTURE","SOLUTION","SYRINGE","TPN","ALL"};
int index = 6;

if(ysite.isSelected()) index = 0;
else if(admixture.isSelected()) index = 1;
else if(solution.isSelected()) index = 2;
else if(syringe.isSelected()) index = 3;
else if(TPN.isSelected()) index = 4;
else if(all.isSelected())index = 5;

the above logic is correct or wrong to select radiobutton ??

Thank you in advance
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> the above logic is correct or wrong to select radiobutton ??

if it works, it's not 'wrong', but perhaps there's a different way:

when creating the radioButtons (usually in a for loop):
set the actionCommand to the index you want
add the radioButton to a ButtonGroup

now , when you want the selected index
buttonGroup.getSelection().getActionCommand();
which will return a String (the index you supplied in the loop).
if you need the index as an int, just parseInt() the String index
 
 
subject: Regarding RadioButton