日期:2014-05-20  浏览次数:20838 次

java计算器程序报错,求讲解
[code=Java][/code]
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Interface extends JFrame implements ActionListener{
/**

*/
private static final long serialVersionUID = 1L;
private JPanel jp1 = new JPanel();
private JPanel jp2 = new JPanel();
private JPanel jpane = new JPanel();
private JTextArea textArea = new JTextArea(1,25);
private double x;
String s = null;
private double add = 0; //标示加数
private double dec = 0; //标示被减数
private double mul = 0; //标示乘数
private double div = 0; //标示被除数
private StringBuffer buffer;
private JButton button_0 = new JButton("0"); 
private JButton button_1 = new JButton("1"); 
private JButton button_2 = new JButton("2"); 
private JButton button_3 = new JButton("3"); 
private JButton button_4 = new JButton("4"); 
private JButton button_5 = new JButton("5"); 
private JButton button_6 = new JButton("6"); 
private JButton button_7 = new JButton("7"); 
private JButton button_8 = new JButton("8"); 
private JButton button_9 = new JButton("9"); 
private JButton button_Point = new JButton("."); 
private JButton button_Add = new JButton("+"); 
private JButton button_Dec = new JButton("-"); 
private JButton button_Mul = new JButton("*"); 
private JButton button_Div = new JButton("/"); 
private JButton button_Cal = new JButton("="); 

public Interface(){
jp2.add(button_7);
button_7.addActionListener(this);
jp2.add(button_8);
button_8.addActionListener(this);
jp2.add(button_9);
button_9.addActionListener(this);
jp2.add(button_Add);
button_Add.addActionListener(this);
jp2.add(button_4);
button_4.addActionListener(this);
jp2.add(button_5);
button_5.addActionListener(this);
jp2.add(button_6);
button_6.addActionListener(this);
jp2.add(button_Dec);
button_Dec.addActionListener(this);
jp2.add(button_1);
button_1.addActionListener(this);
jp2.add(button_2);
button_2.addActionListener(this);
jp2.add(button_3);
button_3.addActionListener(this);
jp2.add(button_Mul);
button_Mul.addActionListener(this);
jp2.add(button_0);
button_0.addActionListener(this);
jp2.add(button_Point);
button_Point.addActionListener(this);
jp2.add(button_Cal);
button_Cal.addActionListener(this);
jp2.add(button_Div);
button_Div.addActionListener(this);
jp2.setLayout(new GridLayout(4, 4));


jp1.add(textArea);

this.add(jpane);
jpane.add(jp1);
jpane.add(jp2);
jpane.setLayout(new BoxLayout(jpane, 1));
this.setTitle("计算器");
this.setBounds(800,300,300,180);
this.setVisible(true);
this.setResizable(false);

}

public void actionPerformed(ActionEvent e) {
if(e.getSource()==button_0){
textArea.append("0");
buffer.append("0");
}
else if(e.getSource()==button_1){
textArea.append("1");
buffer.append("1");
}
else if(e.getSource()==button_2){
textArea.append("2");
buffer.append("2");
}
else if(e.getSource()==button_3){
textArea.setText("3");
buffer.append("3");
}
else if(e.getSource()==button_4){
textArea.append("4");
buffer.append("4");
}
else if(e.getSource()==button_5){
textArea.append("5");
buffer.append("5");