Results 1 to 7 of 7
  1. #1
    riddhikarnik is offline Member
    Join Date
    Jun 2009
    Posts
    1
    Rep Power
    0

    Question RadioButton selections in an Exam application

    Hi,
    i am trying to create an application for taking online examinations, the Multiple Choice kind of.
    i have designed the GUI, a textarea to display the question and then 4 radio buttons for selecting one answer. i have NEXT and PREVIOUS buttons to scroll through all the questions..My problem is on clicking next, the radiobuttons are not getting deselected, in spite of my code of calling

    setSelected(false)

    on each of the radio buttons.. is there any other way?? moreover how can i make this easy to always clear off the selected buttons for the next question..?? i mean some group kinda thing for all those buttons...

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Are you using a ButtonGroup object here and are all the JRadioButtons added to this object?

    If not, please have a look here: How to Use Radio Buttons

    If you are using Java 1.6, you can clear the group via a call to the clearSelection() method.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    If you are using Java 1.6, you can clear the group via a call to the clearSelection() method.
    Working with the ButtonGroup is the most suitable way in UI designing.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Eranga View Post
    Working with the ButtonGroup is the most suitable way in UI designing.
    yes, clearSelection is called on the ButtonGroup object, but it won't work if you compile with 1.5 or previous.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I think that another way to clear the selection if using Java 1.5 or prior is to create a dummy JRadioButton that is added to the ButtonGroup but not to a visible component and thus it is never seen. When wanting to clear the selection, just call setVisible(true) on the dummy button. I believe that this is kosher (anyone, please correct me if this is wrong).

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    You are correct Fubarable, 100% correct. I comes with this scenario several times, after updating my JDK versions time-to-time with the newer version. Actually this type of things happen several instance in different implementations. I don't know why Suns' people not caring about this.

Similar Threads

  1. freeze radioButton without disable them
    By itaipee in forum AWT / Swing
    Replies: 5
    Last Post: 05-25-2009, 09:29 AM
  2. RadioButton
    By tiger100plus in forum New To Java
    Replies: 1
    Last Post: 01-05-2009, 08:04 PM
  3. please help with exam problems
    By Nari in forum New To Java
    Replies: 4
    Last Post: 04-21-2008, 08:47 PM
  4. radiobutton selection
    By newtojava7 in forum New To Java
    Replies: 1
    Last Post: 03-17-2008, 02:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •