Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Regarding RadioButton

Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
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
Hold that thought. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic