package homework;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Calculator implements ActionListener{
private JTextField jtf = new JTextField(10); String lastcommand = "=";
double result = 0;
boolean start = true;

public Calculator() {
JFrame jf = new JFrame("计算器");
jf.add(jtf, BorderLayout.NORTH);
JPanel jp = new JPanel();
GridLayout gl = new GridLayout(5,4);
jp.setLayout(gl);
String[] lab = {"backs","CE","C","+",
"7","8","9","-",
"4","5","6","*",
"1","2","3","/",
"0",".","+/-","=",};
JButton[] jb = new JButton[lab.length];
for (int i=0; i<jb.length; i++){
jb[i] =  new JButton(lab[i]);
jb[i].addActionListener(this);
jp.add(jb[i]);
}
jf.add(jp);

jf.setSize(300,200);
jf.setLocation(300,200);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent ae){
//将按钮的值显示到文本框中
// String input = ae.getActionCommand();
// if (start){
// jtf.setText("");
// start = false;
// }
// jtf.setText(jtf.getText()+ input);//将按钮上的符号显示到文本框中
// String command = ae.getActionCommand();
// if (start){
// if (command.equals("-")){
// jtf.setText(command);
// start = false;
// }
// else {
// lastcommand = command;
// }
// }
//调用方法,将文本框里的值传入方法,计算结果
// else {
// this.calculator(Double.parseDouble(jtf.getText()));
// lastcommand = command;
// start = true;
// }

}
public void calculator(double x){
if (lastcommand.equals("+")){
result += x;
}
else if (lastcommand.equals("-")){
result -= x;
}
else if (lastcommand.equals("*")){
result *= x;
}
else if (lastcommand.equals("/")){
result /= x;
}
else if (lastcommand.equals("=")){
result = x;
}
jtf.setText(result+"");
}

public static void main(String[] args){
new Calculator();
}
}注释起来的代码 有问题,编译出异常,问下大家,怎么改才能实现计算器的功能呀?