Results 1 to 5 of 5

Thread: Need Help

  1. #1
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Default JCheckBox and JRadioButton

    the problem is done
    Last edited by TheUltimateFortress; 04-30-2010 at 06:23 AM.

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

    Default

    1) Use your radio button results and if blocks to create Strings:

    Java Code:
    if (myRadio.isSelected()) {
       someString += "Fubars, ";
    }
    2) To make your code more easily read in the forum, use spaces, not tabs for indentation. Three to four spaces usually works nicely.

    3) To help forum members know what your thread is about at a glance, please use a more informative thread title. "Need Help" doesn't say much as most all threads are posted because the OP needs help.

    Much luck and hope this helps!

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

    Default

    For me what you are asking is not clear enough. And also as Fubarable says, your thread title is not appropriate. Better to use a meaningful title next time.

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

    Default

    Again, have you tried my suggestion number 1 above?

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

    Default

    Quote Originally Posted by TheUltimateFortress View Post
    Fubarable thank your the reply.
    I've tried. Where should I put that string
    You're creating a humongous String called string1 (you will want to choose better more descriptive names for your variables as it will make your code much easier to understand), that is holding the summary of all the rental information, and presently you are trying to get information from some JRadioButtons like so:

    Java Code:
    + "\nOptional : " + gps.isSelected() + insurance.isSelected()

    Since isSelected returns either true or false, there should be no surprise that this will result in an output that will look something like:

    Java Code:
    Optional: truefalse

    Instead I'd create several smaller Strings, one for each set of radiobuttons, for instance one called optionsString that summarizes the results found in the options collection of radio buttons, and do this before creating your humongous string1. It could look something like so:

    Java Code:
    String optionsString = "Options: ";
    if (gps.isSelected()) {
      optionsString += "GPS ";
    }
    // may need an else here if this group of JRadioButtons use a ButtonGroup 
    // and selecting one exludes selecting another
    if (insurance.isSelected()) {
      optionsString += "Insurance ";
    }

    And then when you create your humongus string1 (which might be better called rentalSummaryString)
    where you have this:

    Java Code:
    + "\nOptional : " + gps.isSelected() + insurance.isSelected()

    instead have this:
    Java Code:
    + "\n" + optionsString
    Note that none of my code has been tested or debugged


    Much luck, and hope this helps

Posting Permissions

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