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.


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

Results 1 to 1 of 1

Thread: Action from Radio Button

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Thanked 0 Times in 0 Posts

    Default Action from Radio Button

    I'm creating a Temperature Converter, and I want the program to do a certain command once a Radio Button option is selected based on that choice.

    What I've done so far; below are the two radio buttons, Fahrenheit to Celsius and Celsius to Fahrenheit and the button Confirm that when clicked performs the action.

    				rdbtnFtoC = new JRadioButton();
    				rdbtnFtoC.setText("Fahrenheit to Celsius");
    				rdbtnFtoC.setBounds(51, 144, 140, 18);
    				rdbtnCtoF = new JRadioButton();
    				rdbtnCtoF.setText("Celsius to Fahrenheit");
    				rdbtnCtoF.setBounds(51, 168, 140, 18);
    				btnConvert = new JButton();
    				btnConvert.setBounds(401, 153, 121, 38);
    				btnConvert.addActionListener(new ActionListener() {
    					public void actionPerformed(ActionEvent evt) {
    						System.out.println("btnConvert.actionPerformed, event="+evt);
    						//TODO add your code for btnConvert.actionPerformed
    						int val = txtInsert.getInt();
    							// Create a command that uses the radio button selection and converts the number in the box using the conversion formula.
    			this.setSize(602, 403);
    		} catch (Exception e) {

    I'm not sure if I can add an if statement, :/ I'm brand new to GUI so not entirely aware of how it works.
    Help please?
    Last edited by Json; April 26th, 2010 at 09:05 AM. Reason: fixed your code tag

Similar Threads

  1. Action Listener
    By kray66 in forum AWT / Java Swing
    Replies: 2
    Last Post: April 19th, 2010, 03:26 PM
  2. Problem with Action Listener
    By JonoScho in forum AWT / Java Swing
    Replies: 4
    Last Post: March 19th, 2010, 01:03 AM
  3. radio buttons stop working
    By tabutcher in forum AWT / Java Swing
    Replies: 2
    Last Post: March 5th, 2010, 09:28 AM
  4. Need Help Action Listener....
    By vhizent23 in forum AWT / Java Swing
    Replies: 2
    Last Post: October 9th, 2009, 01:46 PM
  5. [SOLVED] Using html Radio Buttons with Servlets
    By oss_2008 in forum Java Servlet
    Replies: 2
    Last Post: June 25th, 2009, 05:39 AM