Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting a RadioButton input

 
Derrick Ritchie
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I appreciate this may be really really simple but I`m having a mental block and hope that someone can help.

I am looking to set up a set of JRadioButtons in a ButtonGroup. Its goigng to look like:

RadioButton one
RadionButton two
JButton OK

The user should press the OK button and this should capture whatever is selected in the radion buttons.

However I cant think how to do this, I assume I attach an actionlistener to each Button but surely this would just mean when they click on the OK the window would close and the selection would not be captured as the event would only register the OKButton.

I`ve looked in java.sun but that has not helped.

Any advice, thanks in advance
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if this helps: Java Swing Tutorial: How to use buttons, etc..
 
Derrick Ritchie
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have checked that site, I`ve had quite a long look but all that shows is what happens when you click the button. However it does not show what happens if an ok button is added into that.

I`ll try to explain it a bit better. I`m going to set up a class that has universal JRadioButtons yes and no. It also has a universal intger ReturnChoice which returns 1 for yes and 0 for no. If I add an actionlistener to all the buttons will the actionPerformed method be able to change from 1 to 0 depending on which option the user chooses? If the user then clicks on OK when the window closes will this choice be remembered so I can call it using a method like getChoice() which would return an integer value?

I really am only scratching the surface of swing so any helps or good book tips are much appreciated
[ February 25, 2006: Message edited by: Derrick Ritchie ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see if this is any closer to what you're after

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic