GUI华氏温度摄氏温度以及k是温度转换
2013-11-24 17:36
309 查看
package com.yd.cn;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Textarea extends JFrame implements ActionListener {
private JButton transformFButton = new JButton("摄氏");
private JButton transformCButton = new JButton("华氏转摄氏");
private JButton transformKButton = new JButton("K氏");
private JTextField fTextField = new JTextField();
private JTextField cTextField = new JTextField();
private JTextField KTextField = new JTextField();
float c, f, k;
public Textarea() {
super("华氏温度摄氏温度转换");
try {
init();
} catch (Exception e) {
e.printStackTrace();
}
}
private void init() {
fTextField.setBounds(10, 30, 100, 25);
cTextField.setBounds(130, 30, 100, 25);
KTextField.setBounds(230, 30, 100, 25);
transformCButton.setBounds(10, 58, 100, 25);
transformFButton.setBounds(130, 58, 100, 25);
transformKButton.setBounds(230, 58, 100, 25);
transformCButton.addActionListener(this);
Container c = getContentPane();
c.add(fTextField);
c.add(cTextField);
c.add(KTextField);
c.add(transformCButton);
c.add(transformFButton);
c.add(transformKButton);
c.setLayout(null);
this.setSize(380, 150);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new Textarea();
}
public void actionPerformed(ActionEvent e) {
// 华氏温度F与摄氏度C
// F= C* 9/5 + 32
// C=(F-32)*5/9
if (e.getSource() == transformCButton) {
try {
f = Float.parseFloat(fTextField.getText());
c = (f - 32) * 5 / 9;
k = c + 273;
cTextField.setText(String.valueOf(c));
KTextField.setText(String.valueOf(k));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Textarea extends JFrame implements ActionListener {
private JButton transformFButton = new JButton("摄氏");
private JButton transformCButton = new JButton("华氏转摄氏");
private JButton transformKButton = new JButton("K氏");
private JTextField fTextField = new JTextField();
private JTextField cTextField = new JTextField();
private JTextField KTextField = new JTextField();
float c, f, k;
public Textarea() {
super("华氏温度摄氏温度转换");
try {
init();
} catch (Exception e) {
e.printStackTrace();
}
}
private void init() {
fTextField.setBounds(10, 30, 100, 25);
cTextField.setBounds(130, 30, 100, 25);
KTextField.setBounds(230, 30, 100, 25);
transformCButton.setBounds(10, 58, 100, 25);
transformFButton.setBounds(130, 58, 100, 25);
transformKButton.setBounds(230, 58, 100, 25);
transformCButton.addActionListener(this);
Container c = getContentPane();
c.add(fTextField);
c.add(cTextField);
c.add(KTextField);
c.add(transformCButton);
c.add(transformFButton);
c.add(transformKButton);
c.setLayout(null);
this.setSize(380, 150);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new Textarea();
}
public void actionPerformed(ActionEvent e) {
// 华氏温度F与摄氏度C
// F= C* 9/5 + 32
// C=(F-32)*5/9
if (e.getSource() == transformCButton) {
try {
f = Float.parseFloat(fTextField.getText());
c = (f - 32) * 5 / 9;
k = c + 273;
cTextField.setText(String.valueOf(c));
KTextField.setText(String.valueOf(k));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
相关文章推荐
- 将华氏温度转换成摄氏温度或将摄氏温度转化成华氏温度。(需考虑多种不合法的情况尽量转化为合法的)
- 小明去美国旅游,美国温度以华氏温度计量,她需要将华氏温度转换为摄氏温度,编写程序实现此功能. 要求: 从控制台输入华氏温度信息,并且分别打印最后的华氏温度和摄氏温度的结果
- 习题6.5;温度转换(华氏温度换为摄氏温度)
- 将摄氏温度转换成华氏温度
- 最简单的方式用C表示摄氏温度和华氏温度的转换
- 输入一个华氏温度,要求输出摄氏温度。公式为 c=5(F-32)/9 输出要求有文字说明,取位2小数。 输入 一个华氏温度,浮点数 输出 摄氏温度,浮点两位小数 样例输入 -40
- 华氏温度与摄氏温度的转换
- 摄氏温度和华氏温度的转换之java算法
- 实现摄氏温度与华氏温度的转换
- python学习-摄氏温度转换华氏温度小程序(graphics)
- C++华氏温度和摄氏温度转换
- Windows server 2012服务器安装和使用以及core和GUI界面之间转换
- 华氏温度--摄氏温度转换
- 华氏温度转换摄氏温度程序
- 汇编语言-华氏温度转换为摄氏温度
- 实现摄氏温度和华氏温度的相互转换
- 练习1-4 编写一个程序打印摄氏温度转换成相应华氏温度的转换表
- 摄氏温度和华氏温度的转换
- 华氏温度与摄氏温度转换简单编程
- 摄氏温度转换华氏温度