怎么用java编写一个计算器

来源:百度知道 编辑:UC知道 时间:2024/05/19 14:08:19
我是一个java初学者,老师布置了一道考题,用java编写一个计算器,要求计算是按照先乘除后加减的计算顺序计算,不是按照输入的顺序计算,那位大虾能帮帮偶 ,偶不胜感激。十万火急

有一个现成的参考一下吧

import java.awt.event.ActionEvent;

public class Application extends JFrame {

protected String str = "";
protected boolean isChar = true;
protected boolean isEqual = false;
protected JTextField textField;

public Application() {
Listener listerner = new Listener(this);
getContentPane().setLayout(null);

JButton button = new JButton("7");
button.addActionListener(listerner);
button.setBounds(12, 69, 43, 27);
getContentPane().add(button);

textField = new JTextField();
textField.setText("0");
textField.setEditable(false);
textField.setHorizontalAlignment(JTextField.RIGHT);
textField.setBounds(12, 22, 377, 27);