import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JTextField;
public class A {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
A window = new A();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public A() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
int count = 0;
private JTextField txt1;
private JTextField txt2;
private JLabel label;
private JLabel label_1;
private void initialize() {
frame = new JFrame();
frame.setTitle("温度转换");
frame.getContentPane().setFont(new Font("华文楷体", Font.PLAIN, 18));
frame.setBounds(100, 100, 450, 108);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
label_1 = new JLabel("华氏温度 :");
label = new JLabel("摄氏温度");
label.setFont(new Font("宋体", Font.PLAIN, 14));
label.setForeground(Color.BLACK);
label.setBounds(22, 20, 77, 29);
frame.getContentPane().add(label);
txt1 = new JTextField();
txt1.setBounds(111, 24, 66, 21);
frame.getContentPane().add(txt1);
txt1.setColumns(10);
JButton button = new JButton(">>");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Double d = Double.valueOf(txt1.getText());
d = d*1.8 + 32;
txt2.setText(d + "");
}
});
JButton button2 = new JButton("<<");
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Double d = Double.valueOf(txt2.getText());
d = (int)((d- 32)/1.8*100)/100.0;
txt1.setText(d + "");
}
});
button.setBounds(210, 23, 33, 23);
frame.getContentPane().add(button);
button2.setBounds(180, 23, 33, 23);
frame.getContentPane().add(button2);
txt2 = new JTextField();
txt2.setBounds(264, 24, 66, 21);
frame.getContentPane().add(txt2);
txt2.setColumns(10);
label_1.setForeground(Color.BLACK);
label_1.setFont(new Font("宋体", Font.PLAIN, 14));
label_1.setBounds(343, 20, 77, 29);
frame.getContentPane().add(label_1);
}
}