Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JRadioButton  RSS feed

 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pat Hays:

if (jRadioButton1.isSelected())
...


Well, he could do that, if he wanted to; but it's often better to handle the ActionEvents sent by each JRadioButton when it is selected, and track the state that way.

This belongs in the Swing/AWT/SWT forum; I'm moving it there for followup.
 
Vallabhaneni Suresh Kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Hays,
Thanks for your reply. But I need the value of the selected radio button so that I can compare the selected radio button value with the actual answer.
 
Vallabhaneni Suresh Kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a frame with a question and four options? I am using radio button to select the answer. How I can get the selected radio button to compare with the actual answer?
 
Pat Hays
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-------------------------------
if(jRadioButton1.isSelected())
{
// TODO: Add any code here
}
else if(jRadioButton2.isSelected())
{
// TODO: Add any code here
}
else if(jRadioButton3.isSelected())
{
// TODO: Add any code here
}
else if(jRadioButton4.isSelected())
{
// TODO: Add any code here
} :roll:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!