Results 1 to 4 of 4
  1. #1
    10e5x is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default Help help.radio buttons

    how to get the value male or female as string from radio button selected by user?code:

    private JRadioButton jRadioButtonMale = null;
    private JRadioButton jRadioButtonFemale = null;
    private ButtonGroup group;

    group = new ButtonGroup();
    group.add(jRadioButtonMale);
    group.add(jRadioButtonFemale);
    private JRadioButton getJRadioButtonMale() {
    if (jRadioButtonMale == null) {
    jRadioButtonMale = new JRadioButton(male);
    jRadioButtonMale.setText("Male");
    jRadioButtonMale.setSize(new Dimension(80, 20));
    jRadioButtonMale.setLocation(new Point(557, 120));
    }
    return jRadioButtonMale;
    }

    private JRadioButton getJRadioButtonFemale() {
    if (jRadioButtonFemale == null) {
    jRadioButtonFemale = new JRadioButton(female);
    jRadioButtonFemale.setText("Female");
    jRadioButtonFemale.setSize(new Dimension(80, 20));
    jRadioButtonFemale.setLocation(new Point(650, 120));
    }


    return jRadioButtonFemale;
    }


    how?help pls

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default

    Check which one is selected and return the appropriate value (whether that is a boolean, a String, an enum, or something else is up to you). Where are you getting stuck with that?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    10e5x is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default

    when i press the submit button. i do not know my String gender = ???????(dunno the selection of my user)

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default

    JRadioButton has an isSelected() method that will tell you whether it has been selected.

    ButtonGroup has a getSelection() method that returns the selected ButtonModel.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Help with Radio Buttons
    By miguelms19 in forum AWT / Swing
    Replies: 3
    Last Post: 06-29-2010, 08:49 PM
  2. Radio Buttons and Jtextfield
    By ogsirus in forum AWT / Swing
    Replies: 7
    Last Post: 05-26-2010, 11:41 PM
  3. Displaying Radio Buttons in JSP
    By kishan in forum Advanced Java
    Replies: 4
    Last Post: 10-23-2009, 04:44 PM
  4. How to use Radio Buttons
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 03:26 PM
  5. radio buttons and paint
    By gtraylo in forum Java Applets
    Replies: 1
    Last Post: 04-19-2008, 01:43 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
  •