import java.awt.*;
import java.awt.event.*;
import java.lang.*;
public class Computer implements ActionListener
{
Frame f;
TextField tf;
Panel p1,p2,p3;
Button bt[] = new Button[10];
   // Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9;
Button jia,jian,cheng,chu,deng;
Button ce,backspace,c,nz,dian;

////////////////////////////////////////////////////
    float result=0.0f;
    String str="";
    boolean flag=true;
    int i=0;
    ////////////////////////////////////////////////////


public void display()
{
f= new Frame("计算器");
f.setSize(300,400);
f.setLocation(320,240);
f.setBackground(Color.lightGray);
// f.setLayout(new FlowLayout(FlowLayout.LEFT));

tf = new TextField(30);
tf.setEditable(false);
f.add(tf);

for(i=0;i<=9;i++)
{
bt[i]= new Button(Integer.toString(i));
p1.add(bt[i]);
bt[i].addActionListener(this);

nz=new Button("+/-");
    dian=new Button(".");
    nz.addActionListener(this);
    dian.addActionListener(this);
    p1.add(nz);
    p1.add(dian);
p1.setLayout(new GridLayout(4,3));

   jia=new Button("+");
   jian=new Button("-");
   cheng=new Button("*");
   chu=new Button("/");
   deng=new Button("=");
   
   ce=new Button("CE");
   backspace=new Button("BACKSPACE");
   c=new Button("C");
   
   
   f.add(jia);
   f.add(jian);
   f.add(cheng);
   f.add(chu);
   f.add(deng);
   f.add(ce);
   f.add(backspace);
   f.add(c);
   
   jia.addActionListener(this);
   jian.addActionListener(this);
   cheng.addActionListener(this);
   chu.addActionListener(this);
   deng.addActionListener(this);
   ce.addActionListener(this);
   backspace.addActionListener(this);
   c.addActionListener(this);
   
   f.addWindowListener(new WinClose());
   f.setVisible(true);
}


public void actionPerformed(ActionEvent e)
{
for(i=0;i<=9;i++)
{

if(e.setSource()==bt[i])
{
str=str+e.getActionCommand();
tf.setText(str);
}
else if(e.getSource()==dian)
{
str=str+".";
tf.setText(str);
}
else if(e.getSource()==jia)
{
result=result+Float.parseFloat(str);
str="";
tf.setText(""+result);
}
else if(e.getSource()==jian)
{
result=result-Float.parseFloat(str);
str="";
tf.setText(""+result);
}
else if(e.getSource()==cheng)
{
result=result*Float.parseFloat(str);
str="";
tf.setText(""+result);//?
}
else if(e.getSource()==chu)
{
if(Float.parseFloat(str)==0)
   System.out.print("除数不能为零");
   
else
{
result=result/Float.parseFloat(str);
    str="";
    tf.setText(""+result);
}
}
    else if(e.getSource()==ce)
    {
     result=0.0f;
     str="";
     tf.setText("0.");
     }
    else if(e.getSource()==c)
    {
     result=0.0f;
     str="";
     tf.setText("0.");
     }
    else if(e.getSource()==nz)
    {  if(flag==false)
        {
         str='-'+str;
         tf.setText(str);
         flag=true;
         }
        else if(flag==true)
        {
         str=str.substring(1,str.length());
         tf.setText(str);
         flag=false;
         }
        
     }
    else if(e.getSource()==backspace)
    {      
           str=str.substring(0,str.length()-1);
           tf.setText(str);
           
     }
}
}

public static void main(String args[])
{
(new Computer()).display();
}


}

class WinClose extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}不好意思  麻烦各位一下
代码全贴出来了