Results 1 to 7 of 7
  1. #1
    pink123 is offline Member
    Join Date
    Feb 2011
    Posts
    84
    Rep Power
    0

    Default Add a question with multiple choice answer

    Hi,

    I have to add a question for which user can select more than 1 value
    Its like this

    Please select

    Choice 1
    Choice 2
    .
    .
    .
    Choice 8

    Shall I use a Jlabel for the question and Jcheckbox for the answers(various option).I have to create 8 check boxes for this
    I am new to Swings .After creating Jlabel and Jcheckbox ,do I have to add actionlistener to all the 8 checkboxes or how will I save the data.i.e How to save multiple choices for 1 question.


    Thanks,

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

    Default

    I would use a JButton, say "submit" or some sort, and in that single JButton's ActionListener, check the state of the JCheckBoxes.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,247
    Rep Power
    19

    Default

    I am new to Swings
    Evidently. It's "Swing" not "Swings' :)

    db

  4. #4
    pink123 is offline Member
    Join Date
    Feb 2011
    Posts
    84
    Rep Power
    0

    Default

    Thanks for the reply.
    According to requirements ,there should be no button.
    But there is a save button on the same page ,which finally saves the data on the page.
    You mean on the actionlistener on this button,I should save the state of checkbox?
    I dont know how to do this?
    Currently there are 8 checkboxes and corressponding 8 actionPerformed method ,I am confused how to save the option user selected.

    Please help.

    Thanks,

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,247
    Rep Power
    19

    Default

    there is a save button on the same page ,which finally saves the data on the page.
    You mean on the actionlistener on this button,I should save the state of checkbox?
    Yes, that's clearly what he means.

    I dont know how to do this?
    Do you know how to determine the state (that means, checked or uncheked) of ONE JCheckBox? If not, go through the API to find the method that will be useful for this (hint: the method is inherited from AbstractButton and starts with "is...").

    You do NOT need ActionListeners on the JCheckBoxes -- because you don't need to perform any action until the "Save" button is clicked.

    db

  6. #6
    pink123 is offline Member
    Join Date
    Feb 2011
    Posts
    84
    Rep Power
    0

    Default

    Thanks a lot I have understood this part but now how do I save this answer that is i need as many java setter as there are checkboxes ?
    Is there any other way to set the value in Java setter ?

    Please help

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,247
    Rep Power
    19

Similar Threads

  1. Replies: 12
    Last Post: 07-27-2010, 09:40 AM
  2. How to loop a question when answer is negatve?
    By brazuca in forum New To Java
    Replies: 6
    Last Post: 04-23-2009, 05:46 AM
  3. Answer To Previous Question
    By herbozo2003 in forum Java Servlet
    Replies: 0
    Last Post: 03-02-2009, 02:22 AM
  4. Plz answer this question ...
    By raghu2114 in forum Advanced Java
    Replies: 2
    Last Post: 09-19-2008, 06:36 PM
  5. Need help with T/F and Multiple Choice
    By sayso36 in forum Advanced Java
    Replies: 0
    Last Post: 03-12-2008, 04:39 PM

Posting Permissions

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