这个计算器不能连续运算...
我做的一个简单的计算器,但是不能连续运算,大家帮我看看。
import java.awt.*;
import java.awt.event.*;
public class Calculatorimplements ActionListener
{
Button bPoint,bEqual,bPlus,bMinus,bClear,bMulti,bDivision;
Button[] b=new Button[10];
boolean isFloat = false;
Panel panel1=new Panel();
Panel panel2=new Panel();
Panel panel3=new Panel();
String currentOp = new String("");
String preOp = new String("");
String foreText = new String("");
String backText = new String("");
TextField tfAnswer=new TextField(8);
Frame jsq=new Frame("计算器");
public void jsqjm (){
jsq.setSize(300,200);
jsq.setLocation(400,100);
jsq.setBackground(Color.PINK);
jsq.addWindowListener(new mc());
for(int i=9;i>=0;i--){
b[i]=new Button(Integer.toString(i));
panel2.add(b[i]);
b[i].addActionListener(this);
}
bPoint = new Button(".");
bEqual=new Button("=");
bEqual.setForeground(Color.red);
bClear = new Button("清除");
bClear.setForeground(Color.red);
bDivision = new Button("/");
bDivision.setForeground(Color.red);
bMulti = new Button("*");
bMulti.setForeground(Color.red);
bMinus = new Button("-");
bMinus.setForeground(Color.red);
bPlus = new Button("+");
bPlus.setForeground(Color.red);
jsq.setLayout(new FlowLayout(FlowLayout.CENTER,5,35));
panel1.setLayout(new FlowLayout());
panel2.setLayout(new GridLayout(4,3));
panel3.setLayout(new GridLayout(4,1));
jsq.add(panel1);
jsq.add(panel2);
jsq.add(panel3);
panel1.add(tfAnswer);
panel1.add(bClear);
bClear.addActionListener(this);
panel2.add(bPoint);
bPoint.addActionListener(this);
panel2.add(bEqual);
bEqual.addActionListener(this);
panel3.add(bPlus);
bPlus.addActionListener(this);
panel3.add(bMinus);
bMinus.addActionListener(this);
panel3.add(bMulti);
bMulti.addActionListener(this);
panel3.add(bDivision);
bDivision.addActionListener(this);
jsq.setVisible(true);
}
public static void main (String[] args)
{
Calculator ftest=new Calculator();
ftest.jsqjm();
}
public void actionPerformed(ActionEvent e)
{
String s=new String("");
s=(String)e.getActionCommand();
if((s!=".")&&(s!="清除")&&(s!="+")&&(s!="-")&&(s!="/")&&(s!="*")&&(s!="="))
{ doForeText(s); }
if(s==".")
{
if(foreText.equals(""))
{
isFloat=true;
foreText+="0.";
tfAnswer.setText(foreText);
}
else
{
if(!isFloat)
doForeText(s);
}
}
if(s=="清除")
{ doClear(); }
if((s=="+")||(s=="-")||(s=="/")||(s=="*"))
{
if(foreText!=" "){
currentOp=s;
doOperator();
}
else { preOp=s; }
}
if(s.equals("="))
{ doOperator(); }
}
public void doOperator(){
double dFore=0,dBack=0,resultNum=0;
Double d;