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

java计算器,高手请进
下面是我写的java计算器的代码,可是生成的计算器中,按键反映都是 "0.0 ",高手帮忙啊!
到底是怎么会事啊?
import   java.awt.*;
import   java.awt.event.*;
public   class   Calculator   extends   Frame   implements   ActionListener   {

private   double   a=0,b=0,sum=0;
int   flag=0,count=0,p=1;
char   mode= '? ';//运算符
private   TextField   display   =new   TextField();
private   Button   one   =new   Button( "1 ");
private   Button   two   =new   Button( "2 ");
private   Button   three   =new   Button( "3 ");
private   Button   four   =new   Button( "4 ");
private   Button   five   =new   Button( "5 ");
private   Button   six   =new   Button( "6 ");
private   Button   seven   =new   Button( "7 ");
private   Button   eight   =new   Button( "8 ");
private   Button   nine   =new   Button( "9 ");
private   Button   zero   =new   Button( "0 ");
private   Button   point   =new   Button( ". ");
private   Button   add   =new   Button( "+ ");
private   Button   sub   =new   Button( "- ");
private   Button   mul   =new   Button( "* ");
private   Button   div   =new   Button( "/ ");
private   Button   result   =new   Button( "= ");
private   Button   clr   =new   Button( "CLR ");
private   Button   quit   =new   Button( "quit ");
private   Label   lable   =new   Label( "计算器 ");

private   class   WindowCloser   extends   WindowAdapter
{
public   void   windowClosing(WindowEvent   e)
{
System.exit(0);
}
}

private   void   setup()//布局管理
{
Panel   top=   new   Panel();
top.setLayout(new   GridLayout(2,1));
top.add(lable);
top.add(display);
Panel   number=new   Panel();
number.setLayout(new   GridLayout(6,3));
number.add(one);
number.add(two);
number.add(three);
number.add(four);
number.add(five);
number.add(six);
number.add(seven);
number.add(eight);
number.add(nine);
number.add(zero);
number.add(add);
number.add(sub);
number.add(point);
number.add(mul);
number.add(div);
number.add(result);
number.add(clr);
number.add(quit);
setLayout(new   BorderLayout());
add( "North ",top);
add( "South ",number);

}

        public   Calculator()  
        {//构造方法
        super( "计算器 ");
        setup();
        one.addActionListener(this);
        two.addActionListener(this);
        three.addActionListener(this);
        four.addActionListener(this);
        five.addActionListener(this);
        six.addActionListener(this);
        seven.addActionListener(this);
        eight.addActionListener(this);