import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.*;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.borland.jbcl.layout.BoxLayout2;
import javax.swing.JPanel;
import javax.swing.JLabel;
/**
*
Title:
*
*
Description:
*
*
Copyright: Copyright (c) 2008
*
*
Company:
*
* @author not attributable
* @version 1.0
*/
public class Frame1 extends JFrame {
public Frame1() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public static void main(String[] args) {
Frame1 f1 =new Frame1();
f1.show();
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
setSize(new Dimension(400, 300));
setTitle("温度准换");
txtNum.setText("");
txtNum.setBounds(new Rectangle(105, 96, 127, 21));
btnSend.addActionListener(new Frame1_btnSend_actionAdapter(this));
btnSend.setBounds(new Rectangle(257, 93, 71, 25));
btnSend.setText("转换");
lbl.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
lbl.setText("输入华氏温度:");
lbl.setBounds(new Rectangle(24, 54, 112, 27));
this.getContentPane().add(lbl);
jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
jLabel1.setText("摄氏温度为:");
jLabel1.setBounds(new Rectangle(23, 138, 99, 16));
this.getContentPane().add(txtResult);
this.getContentPane().add(jLabel1);
this.getContentPane().add(txtNum);
this.getContentPane().add(btnSend);
txtResult.setBounds(new Rectangle(101, 172, 130, 21));
}
JTextField txtNum = new JTextField();
JTextField txtResult = new JTextField();
JButton btnSend = new JButton();
BoxLayout2 boxLayout21 = new BoxLayout2();
JLabel lbl = new JLabel();
JLabel jLabel1 = new JLabel();
public void btnSend_actionPerformed(ActionEvent e) {
double douNum = 0;
try {
douNum = this.Result(txtNum.getText().toString());
txtResult.setText(douNum + "");
} catch (Exception ex) {
txtResult.setText("输入错误");
}
}
public double Result(String strNum) {
double douNum = 0;
douNum = (5.0 / 9) * (Double.parseDouble(strNum) - 32);
return douNum;
}
}
class Frame1_btnSend_actionAdapter implements ActionListener {
private Frame1 adaptee;
Frame1_btnSend_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnSend_actionPerformed(e);
}
}