Results 1 to 4 of 4
  1. #1
    javanator is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default Radio Button help!

    Ok so I'm creating a Temperature Converter where Im trying to create a command based on the clicked radio button.

    rdbtnFtoC is the radio button for converting from Fahrenheit to Celsius.
    I want the code to be so that once this option is selected and the convert button is clicked, the value input by the user is converted using a formula.

    Java Code:
    	public void actionPerformed(ActionEvent evt) {
    						System.out.println("btnConvert.actionPerformed, event="+evt);
    						//TODO add your code for btnConvert.actionPerformed
    						int val = [B]txtInsert.getY()[/B]; 
    						if(rdbtnFtoC.equals(true)){
    							val = ((val-32)*(5/9)); 
    						}
    						[B]lblResult.set(val); [/B]
    I'm having trouble saying that if the radio button is selected then execute this code. I don't know if I can use the above if statement in the code,
    And I'm also having trouble with txtInsert.get (integer) but there seems to be no option for integer :/ and outputting an integer (both in bold)

    Help please?

  2. #2
    camickr is online now Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    I'm having trouble saying that if the radio button is selected then execute this code
    You need to use the "isSelected()" method.

  3. #3
    javanator is offline Member
    Join Date
    Mar 2010
    Posts
    5
    Rep Power
    0

    Default

    Ok I tried out the isSelected() method. But I'm still not getting any output :/

    Java Code:
    public void actionPerformed(ActionEvent evt) {
    						System.out.println("btnConvert.actionPerformed, event="+evt);
    						
    						int val = txtInsert.getY();
    						boolean b = rdbtnFtoC.isSelected();
    							if(b){
    								int out = ((val-32)*(5/9));
    								lblResult.equals(out); 
    							}
    						boolean c = rdbtnCtoF.isSelected();
    							if(c){
    								int out2 = ((val+32)*(9/5));
    								lblResult.equals(out2); 
    							}
    						}
    Sorry if I seem like such a n00b

  4. #4
    camickr is online now Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    Well add some System.out.println(...) statements to you code to see what is being executed. Or use a debugger to step through the code to see what is happening.

Similar Threads

  1. Disable Radio button
    By AJG in forum New To Java
    Replies: 3
    Last Post: 05-10-2011, 11:09 AM
  2. Radio button dot color
    By Psyclone in forum AWT / Swing
    Replies: 3
    Last Post: 02-21-2010, 04:29 AM
  3. How can I catch the radio button action in jsp?
    By srinivas2828 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 09-18-2009, 04:05 PM
  4. radio button checked by default
    By whiteasshweta in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 07-06-2009, 01:11 PM
  5. How to use SWT Radio Button
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-25-2008, 02:25 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
  •