• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting a RadioButton input

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see if this is any closer to what you're after

 
What's that smell? Hey, sniff this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic