Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Assigning a variable through a radio button selection

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Location
    Chino CA
    Posts
    5
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Assigning a variable through a radio button selection

    I think I'm making this harder then it should be. I'm trying to create a shopping project, for my java programming course, that uses a JFrame GUI to input, calculate and display inputs.
    The meat and potatoes of the project that I'm having difficulty with deals with the assigning of variables following option inputs of radio buttons, a check box calculated against a quantity from a text field.

    I have the components set up graphically as such:

    O Blue O Red O Yellow □ Engrave
    quantity ["quantityTextField"]

    Now I need to display the following depending on which radio button is selected, if the engrave check box is selected, and a monetary subtotal like the following:

    Object Color Quantity Engraved Total
    Blue 1 Yes $15.00
    Red 2 No $22.00
    Yellow 1 No $11.00

    Sorry if I had to describe this so poorly, I don't have any experience programming. I just need help figuring out how to assign an int or double like "blueQuantityDouble" after selecting a color, and inputting a quantity, and then hitting a calculate button. Thanks in advance for any help you can throw my way. If you need me to clarify, I can do so.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Assigning a variable through a radio button selection

    An ActionListener would allow you to monitor when a radio button is selected and act accordingly. See the following:
    How to Write an Action Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)

Similar Threads

  1. Assigning an 'int' from a JTextField to a variable...
    By RiskyShenanigan in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 26th, 2011, 04:00 PM
  2. need help Coding RADIO BUTTON for REMEMBER ME
    By timosoft in forum Java Theory & Questions
    Replies: 3
    Last Post: February 4th, 2011, 05:19 PM
  3. Adding Radio Button Values
    By bazazu in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 13th, 2010, 10:41 AM
  4. Action from Radio Button
    By halfwaygone in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 25th, 2010, 10:52 AM
  5. Assigning variable to an Array
    By sridevi in forum Collections and Generics
    Replies: 3
    Last Post: August 10th, 2009, 10:58 PM