package homeWork13;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class TempertureConvert extends JFrame {// 温度转换,摄氏,华氏,开式
private static final long serialVersionUID = 1L;
private JLabel fromJLabel, enterJLabel, toJLabel, outJLabel;
private JRadioButton fahFromRadioButton, celFromRadioButton,
kelFromRadioButton, fahToRadioButton, celToRadioButton,
kelToRadioButton;
private ButtonGroup fromButtonGroup, toButtonGroup;
private JTextField inputField, outputField;
private JPanel converToJPanel,convertFromJPanel;
private int tempFrom,tempTo;
public TempertureConvert() {
super("Temperture Convert");
// 创建GUI
fromJLabel = new JLabel("Convert From:");
fahFromRadioButton=new JRadioButton("Fahrenheit");
celFromRadioButton=new JRadioButton("Celcius");
kelFromRadioButton=new JRadioButton("Kelvin");
fromButtonGroup=new ButtonGroup();//使用按钮组,使得一次只能选中一个按钮
fromButtonGroup.add(fahFromRadioButton);
fromButtonGroup.add(celFromRadioButton);
fromButtonGroup.add(kelFromRadioButton);
enterJLabel=new JLabel("Enter Numeric Temperature:");
inputField=new JTextField(10);
toJLabel=new JLabel("Convert to:");
fahToRadioButton=new JRadioButton("Fahrenheit");
celToRadioButton=new JRadioButton("Celcius");
kelToRadioButton=new JRadioButton("Kelvin");
toButtonGroup=new ButtonGroup();
toButtonGroup.add(fahToRadioButton);
toButtonGroup.add(celToRadioButton);
toButtonGroup.add(kelToRadioButton);
outJLabel=new JLabel("Comparable Temperature:");
outputField=new JTextField(10);
outputField.setEditable(false);
convertFromJPanel=new JPanel();
convertFromJPanel.setLayout(new GridLayout(1,3));//一行三列的表格
convertFromJPanel.add(fahFromRadioButton);
convertFromJPanel.add(celFromRadioButton);
convertFromJPanel.add(kelFromRadioButton);
converToJPanel=new JPanel();
converToJPanel.setLayout(new GridLayout(1,3));
converToJPanel.add(fahToRadioButton);
converToJPanel.add(celToRadioButton);
converToJPanel.add(kelToRadioButton);
Container container=getContentPane();
container.setLayout(new GridLayout(8,1));
container.add(fromJLabel);
container.add(convertFromJPanel);
container.add(enterJLabel);
container.add(inputField);
container.add(toJLabel);
container.add(converToJPanel);
container.add(outJLabel);
container.add(outputField);
inputField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {//按下回车,进行温度转换
// TODO Auto-generated method stub
tempFrom=Integer.parseInt(event.getActionCommand());
if(fahFromRadioButton.isSelected()&&fahToRadioButton.isSelected())
tempTo=tempFrom;
else if(fahFromRadioButton.isSelected()&&celToRadioButton.isSelected())
tempTo=(int)(5.0f/9.0f*(tempFrom-32));
else if(fahFromRadioButton.isSelected()&&kelToRadioButton.isSelected())
tempTo=(int)(5.0f/9.0f*(tempFrom-32))+273;
else if(celFromRadioButton.isSelected()&&fahToRadioButton.isSelected())
tempTo=(int)(9.0f/5.0f*tempFrom+32);
else if(celFromRadioButton.isSelected()&&celToRadioButton.isSelected())
tempTo=tempFrom;
else if(celFromRadioButton.isSelected()&&kelToRadioButton.isSelected())
tempTo=tempFrom+273;
else if(kelFromRadioButton.isSelected()&&fahToRadioButton.isSelected())
tempTo=(int)(9.0f/5.0f*(tempFrom+273)+32);
else if(kelFromRadioButton.isSelected()&&celToRadioButton.isSelected())
tempTo=tempFrom-273;
else if(kelFromRadioButton.isSelected()&&kelToRadioButton.isSelected())
tempTo=tempFrom;
outputField.setText(tempTo+"");
}
});
setSize(280, 225);
setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TempertureConvert application=new TempertureConvert();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
分享到:
相关推荐
华氏与摄氏温度的转换,根据显示温度转换该温度下的季节图案,程序运行时要要背景音乐而且可以控制播放课停止。
用python实现华氏温度何摄氏温度转换
根据公式将华氏温度转换为摄氏温度和绝对温度
python 将华氏温度转换为摄氏温度 示例
c++源码--华氏温度转换成摄氏温度c++源码--华氏温度转换成摄氏温度
人机交互课程的作业,实现摄氏度到华氏温度的温度转换功能。满足高效率、人性化。
华软软件学院Python软件编程的课件一,技术老但是主要是简单,可以帮助新手培养兴趣。 该课件是说温度转换方面的实例。
提出一种NTC(负温度系数热敏电阻)温度转换的无损压缩解压缩算法,主要用于在使用单片机进行温度转换时,将调用的表格数据进行压缩,解决了单片机A/D转换时存在的表格数据量大、占用存储空间大的问题。
原则——速度:移位>乘法>除法。 做法—180/1.8=180*x 解此一元方程则是0.5555….无限循环。5/9也刚好是0.5555
摄氏度与华氏度温度转换,存在温度上限与下限的限制
根据采样的PT1000阻值,可以计算其对应关系,程序采用二分查找法
怎么去实现由摄氏温度转化为华氏温度!其中用了比较短的代码,非常简洁!
这个程序的功能是:用C++完成华氏温度到摄氏温度的转换
为了实现温度转换,在电烙铁的原电路中添加以下元器件:波段控制开关、整流二级管、稳压二极管、发光二极管等,其电路原理图如图1所示。当电烙铁正常工作时,波段控制开关SB闭合,220V交流电通过常闭开关直接加在...
用于将输入的华氏温度可以转换成摄氏温度,或者将输入的摄氏温度转换成华氏温度,根据显示的温度,能自动切换窗口背景的图案
对温度的值进行转换,用vc的技术,课堂设计的小程序。
这是关于摄氏温度和华氏温度之间转换的,输入转换温度的格式是:21c 或者31f 单位大小写不限制
热敏电阻(电阻信号)→变送器(数字信号)→西门子SMART PLC (数字转换)
用C语言编写一个下程序,要求:将摄氏温度转换成华氏温度,其中参考公式为 fahren=(9.0/5.0)*celsius+32.0;
可以实现摄氏温度转换为华氏温度 希望可以一起交流C#编程