Important alert: (current site time 7/15/2013 4:07:10 PM EDT)
 

VB icon

Temperature Converter

Email
Submitted on: 2/3/2002 8:18:14 PM
By: Randy McCleary 
Level: Intermediate
User Rating: By 8 Users
Compatibility: Java (JDK 1.2)
Views: 33496
(About the author)
 
     This is just a simple java applet that will convert Degrees Fahrenheit to Degrees Celesius. Very simple and can be modified to convert back.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Temperature Converter
// Description:This is just a simple java applet that will convert Degrees Fahrenheit to Degrees Celesius. Very simple and can be modified to convert back.
// By: Randy McCleary
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=2627&lngWId=2//for details.//**************************************

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.text.DecimalFormat;
public class temperature extends JApplet implements ActionListener
{
JLabel lblFahrenheit;
JLabel lblCelsius;
JLabel outputCelsius;
JTextField txtFahrenheit;
double degreesFahrenheit;
FlowLayout layout;
public void init()
{
 Container c = getContentPane();
 
 layout = new FlowLayout();
 layout.setAlignment( FlowLayout.LEFT);
 c.setLayout(layout);
 // instantiate JLabel object for Degrees Fahrenheit
 lblFahrenheit = new JLabel("Enter Fahrenheit and press enter: ");
 // instantiate JTextField object for the degrees fahrenheit
 txtFahrenheit = new JTextField(10);
 // instantiate JLabel object for Degrees Celesius
 lblCelsius = new JLabel("Degrees Celesius: ");
 // JLabel to display the equivalent degrees Celsius
 outputCelsius = new JLabel("");
 c.add(lblFahrenheit);
 //CALL the addActionListener() method on the JTextField object
 // for the degrees Fahrenheit
 txtFahrenheit.addActionListener(this);
 // Add the textbox the celsius label and output label
 c.add(txtFahrenheit);
 c.add(lblCelsius);
 c.add(outputCelsius);
}
public void actionPerformed(ActionEvent e)
{
 // Create a new decimal format to one digit
 DecimalFormat oneDigit = new DecimalFormat("0.0");
 // Get the input
 double Fahrenheit = Double.parseDouble(e.getActionCommand());
 //ASSIGN the result of CALL Celsius function
 double celsius = Celsius(Fahrenheit);
 //Display the results in the label
 outputCelsius.setText(oneDigit.format(celsius));
}
public double Celsius(double Fahrenheit)
{
 double celsius;
 //Formulat to convert Farhrenheit to celsius
 celsius = 5.0 / 9.0 * ( Fahrenheit - 32);
 return celsius;
}
}


Other 6 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

2/23/2002 11:38:34 AMMark Swart

Great program, glad I found some strings inside of it. Thanks buddy. keep developing.!!!
(If this comment was disrespectful, please report it.)

 
11/11/2002 4:24:23 AM

Why I can'run your code .It return
"java.lang.NoSuchMethodError: main
Exception in thread "main" Exit code: 1
There were errors"

Please Help me.Thank you very much.
(If this comment was disrespectful, please report it.)

 
1/19/2005 7:23:01 PM

Very nice. I like how you commented on each step.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.