java简易计算器,不知道哪里的错误,最后计算结果都是0.0
package keshihua;import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Ksh11 extends JFrame implements ActionListener
{
static JPanel pan=new JPanel();
static JTextField tf=new JTextField("");
static JButton[] b=new JButton[10];
static JButton bc,bm,bd,ba,be,bdot;
public static void main(String[] args)
{
Ksh11 frm=new Ksh11();
for(int i=0;i<=9;i++)
{
b[i]=new JButton(""+i);
}
bdot=new JButton(" . "); ba=new JButton("+"); bd=new JButton("-");
bm=new JButton("*"); bc=new JButton("/"); be=new JButton("=");
frm.setTitle("网格式布局管理器 Gridlayout");
frm.setLayout(null);
frm.setSize(300, 220);
frm.setResizable(true);
GridLayout grid=new GridLayout(4,4);
tf.setBounds(35, 15, 200, 25);
pan.setBounds(35, 50, 200, 130);
tf.setBackground(Color.CYAN);
tf.setHorizontalAlignment(JTextField.RIGHT);
pan.add(b[7]); pan.add(b[8]); pan.add(b[9]); pan.add(bc);
pan.add(b[4]); pan.add(b[5]); pan.add(b[6]); pan.add(bm);
pan.add(b[1]); pan.add(b[2]); pan.add(b[3]); pan.add(bd);
pan.add(b[0]); pan.add(bdot); pan.add(be); pan.add(ba);
b[0].addActionListener(frm);
b[1].addActionListener(frm);
b[2].addActionListener(frm);
b[3].addActionListener(frm);
b[4].addActionListener(frm);
b[5].addActionListener(frm);
b[6].addActionListener(frm);
b[7].addActionListener(frm);
b[8].addActionListener(frm);
b[9].addActionListener(frm);
bc.addActionListener(frm);
bm.addActionListener(frm);
bd.addActionListener(frm);
ba.addActionListener(frm);
be.addActionListener(frm);
bdot.addActionListener(frm);
frm.add(tf);
frm.add(pan);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int bz=0;
double flag1=0,flag2=0,flag3=0;
if(e.getSource()==bdot){
tf.setText("0.");
}
else if(e.getSource()==b[0]){
tf.setText(tf.getText()+"0");
flag2=Double.parseDouble(tf.getText());
}
else if(e.getSource()==b[1]){
tf.setText(tf.getText()+"1");
flag2=Double.parseDouble(tf.getText());
}
else if(e.getSource()==b[2]){
tf.setText(tf.getText()+"2");
flag2=Double.parseDouble(tf.getText());
}
else if(e.getSource()==b[3]){
tf.setText(tf.getText()+"3");
flag2=Double.parseDouble(tf.getText());
}
else if(e.getSource()==b[4]){
tf.setText(tf.getText()+"4");
flag2=Double.parseDouble(tf.getText());
}
else if(e.getSource()==b[5]){
tf.setText(tf.getText()+"5");
flag2=Double.parseDouble(tf.getText());
}
else if(e.getSource()==b[6]){
tf.setText(tf.getText()+"6");
flag2=Double.parseDouble(tf.getText());
}
else if(e.getSource()==b[7]){
tf.setText(tf.getText()+"7");
flag2=Double.parseDouble(tf.getText());
}
else if(e.getSource()==b[8]){
tf.setText(tf.getText()+"8");
flag2=Double.parseDouble(tf.getText());
}
else if(e.getSource()==b[9]){
tf.setText(tf.getText()+"9");
flag2=Double.parseDouble(tf.getText());
}
else if(e.getSource()==ba){
tf.setText(tf.getText()+"+");
flag1=flag2;
bz=0;
}
else if(e.getSource()==bd){
tf.setText(tf.getText()+"-");
flag1=flag2;
bz=1;
}
else if(e.getSource()==bm){
tf.setText(tf.getText()+"*");
flag1=flag2;
bz=2;
}
else if(e.getSource()==bc){
tf.setText(tf.getText()+"/");
flag1=flag2;
bz=3;
}
else if(e.getSource()==be){
if(bz==0){
flag3=flag1+flag2;
}
else if(bz==1){
flag3=flag1-flag2;
}
else if(bz==2){
flag3=flag1*flag2;
}
else if(bz==3){
flag3=flag1/flag2;
}
tf.setText(tf.getText()+"="+flag3);
System.out.println(flag3);
System.out.println(flag2);
System.out.println(flag1);
}
}
}