import java.awt.event.*;
import javax.swing.*;
import java.math.BigDecimal;
@SuppressWarnings("serial")
public class Transmit extends JFrame {
private JTextField TF_dollar;
private JTextField TF_RMB;
public Transmit() {
JFrame JF = this;
JF.setTitle("Corrency Converter");
JF.setBounds(100, 100, 400, 300);
JF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JF.setLayout(null);
JLabel JL_dollar = new JLabel("Dollar");
JLabel JL_RMB = new JLabel("RMB");
TF_dollar = new JTextField(10);
TF_RMB = new JTextField(10);
JL_dollar.setBounds(100, 60, 100, 20);
TF_dollar.setBounds(150, 60, 100, 20);
JL_RMB.setBounds(100, 100, 100, 20);
TF_RMB.setBounds(150, 100, 100, 20);
JF.add(JL_dollar);
JF.add(TF_dollar);
JF.add(JL_RMB);
JF.add(TF_RMB);
JButton JB = new JButton("Dollar to RMB");
JButton JB1 = new JButton("RMB to Dollar");
JB.setBounds(100, 140, 150, 20);
JB1.setBounds(100, 180, 150, 20);
JF.add(JB);
JF.add(JB1);
JB.addActionListener(new ButtonClick());
JB1.addActionListener(new ButtonClick1());
}
public static void main(String[] args) {
Transmit f = new Transmit();
f.setVisible(true);
}
class ButtonClick implements ActionListener {
@Override
public void actionPerformed(ActionEvent arg0) {
double dollar = Double.parseDouble(TF_dollar.getText());
double rmb = dollar * 6.5773;
BigDecimal bg = new BigDecimal(rmb);
double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
TF_RMB.setText("" + f1);
}
}
class ButtonClick1 implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
double rmb = Double.parseDouble(TF_RMB.getText());
double dollar = rmb * 0.1520;
BigDecimal bg = new BigDecimal(dollar);
double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
TF_dollar.setText("" + f1);
}
}
}
南邮java实验一—综合图形界面程序设计
最新推荐文章于 2022-12-20 17:45:08 发布