Results 1 to 7 of 7
  1. #1
    acat is offline Member
    Join Date
    Apr 2011
    Posts
    11
    Rep Power
    0

    Default Help, JFrame Array with RadionButton

    If I want to write the code of Array with RadionButton, how to write it.
    for example, there are some selections, S1, S2, S3, S4, and each selections with the different price, $10, $11, $13, $17. Those selections should put a RadioButton group, using an Arrray. when select one of them, the JLable should appear the selection and the price.
    someone can help me???
    I need you help!!!!!

  2. #2
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Your wording makes your question confusing.
    Do you want to create an array of JRadioButton, put it in a ButtonGroup, and when user selects one of them, update a JLabel to output the selection?

  3. #3
    acat is offline Member
    Join Date
    Apr 2011
    Posts
    11
    Rep Power
    0

    Default

    yes, yes exactly!

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default

    Creating an array of RadioButtons is no different than any other array. What exact problems are you having?

  5. #5
    acat is offline Member
    Join Date
    Apr 2011
    Posts
    11
    Rep Power
    0

    Default

    I just do not know how to write the code, it is quite different than the Jbutton, I know how to do it of the button, but for the radiobutton I'm lost !!

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default

    HUH?
    Java Code:
    JRadioButton[] radioButtonList = new JRadioButton[numberOfButtons];
    loop {
        create a new JRadioButton;
        add it to array;
    }

  7. #7
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    For your example, I see no need to even have an array of JRadioButton. You only need to create them, add them to ButtonGroup, add them to the JFrame, and add an ChangeListener on each one. In the actual listener method, you would do event.getSource() to get the calling button.

Similar Threads

  1. (jframe) get a variable out of array list
    By joelharkes in forum New To Java
    Replies: 9
    Last Post: 07-08-2010, 10:38 PM
  2. Replies: 5
    Last Post: 06-14-2010, 06:10 PM
  3. Replies: 6
    Last Post: 04-12-2010, 11:33 AM
  4. Replies: 4
    Last Post: 04-22-2009, 11:02 PM
  5. Replies: 8
    Last Post: 03-21-2009, 09:34 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
  •