摄氏温度和华氏温度的互换(Convert between Celsius and Fahrenheit temperature)
来源:互联网 发布:淘宝村小二 编辑:程序博客网 时间:2024/06/06 19:01
Java Applet,可实现摄氏温度和华氏温度的一键换算:
package example;//Convert between Celsius and Fahrenheit temperature//Java how to program, 5/e, Exercise 6.23//Neglect the error message when closing the applet since it is a JDK bug (id:5098186)import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.text.*;public class Celsius_Fahrenheit extends JApplet implements ActionListener {double celsius,fahrenheit;String celsiusText,fahrenheitText;JLabel CelsiusLable,FahrenheitLable;JTextField CelsiusField,FahrenheitField;DecimalFormat twoDigits=new DecimalFormat("0.00");public void init(){ Container container=getContentPane(); container.setLayout(new FlowLayout()); CelsiusLable= new JLabel("Enter Celsius Temperature:"); container.add(CelsiusLable); CelsiusField=new JTextField(10); container.add(CelsiusField); CelsiusField.addActionListener(this); FahrenheitLable= new JLabel("Enter Fahrenheit Temperature:"); container.add(FahrenheitLable); FahrenheitField=new JTextField(10); container.add(FahrenheitField); FahrenheitField.addActionListener(this); }public void actionPerformed (ActionEvent event){ if (event.getSource()==CelsiusField) { celsius=Double.parseDouble(CelsiusField.getText()); fahrenheit=celsius*9.0/5.0+32; fahrenheitText=twoDigits.format(fahrenheit); FahrenheitField.setText(fahrenheitText); } else if (event.getSource()==FahrenheitField) { fahrenheit=Double.parseDouble(FahrenheitField.getText()); celsius=(fahrenheit-32)*5.0/9.0; celsiusText=twoDigits.format(celsius); CelsiusField.setText(celsiusText); } }}
运行截屏:
- 摄氏温度和华氏温度的互换(Convert between Celsius and Fahrenheit temperature)
- 摄氏温度和华氏温度的转换
- 实现摄氏温度和华氏温度的相互转换
- c++摄氏温度和华氏温度的装换
- 摄氏温度和华氏温度转换
- 华氏温度和摄氏温度
- 摄氏温度 华氏温度 的转换
- Fahrenheit-Celsius table
- 摄氏温度和华氏温度转换改进
- C++华氏温度和摄氏温度转换
- 华氏温度和摄氏温度互相转换
- 华氏温度与摄氏温度的转化
- 华氏温度与摄氏温度的转换
- 使用javascript实现华氏温度和摄氏温度的转化
- 摄氏温度和华氏温度的转换之java算法
- [C1.2] Fahrenheit-Celsius Table
- 输入华氏温度和摄氏温度转化表
- 实现摄氏温度与华氏温度的转换
- DataGrid导出到Excel
- 建立基于WEB的BI图表
- 虚拟方法的重写和静态方法的调用
- 针对 通达信分时图数据结构 的疑问
- Scrum软件开发
- 摄氏温度和华氏温度的互换(Convert between Celsius and Fahrenheit temperature)
- 你好吗?Struts 2-第一次亲密接触----- 一个完整的struts 2 Hello World程序(5)
- 如何隐藏HTML表格的四个边框
- LyNews『凌云新闻』 - 在JAVA文件中获取该项目的相对路径
- JavaScript操纵DOM纠错两则
- C++中几个比较不常用的关键字
- MMS subject 编码中的Charset为何是0xEA
- Windows下常见Oracle服务介绍
- Linux pipe