import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.lang.String;
import java.lang.Integer;
public class jisuanqi extends Applet implements ActionListener
{
static String xianshi;
static float caozuoshu,jieguo;
int biaoji,yunsuanfu,zhengfuhao;
TextField text;
Button n1,n2,n3,n4,n5,n6,n7,n8,n9,n0,point,minus,plus,subtract,multiply,divild,equal,back,ce;
public void init()
{
xianshi=new String("");
caozuoshu=0;
jieguo=0;
biaoji=-1;
yunsuanfu=0;
zhengfuhao=0;
text=new TextField(11);
text.setEditable(false);
text.setText("");
n1=new Button("1");
n2=new Button("2");
n3=new Button("3");
n4=new Button("4");
n5=new Button("5");
n6=new Button("6");
n7=new Button("7");
n8=new Button("8");
n9=new Button("9");
n0=new Button("0");
point=new Button(".");
minus=new Button("-/+");
plus=new Button("+");
subtract=new Button("-");
multiply=new Button("*");
divild=new Button("/");
equal=new Button("=");
back=new Button("back");
ce=new Button("ce");
add(text);
add(n1);
add(n2);
add(n3);
add(n4);
add(n5);
add(n6);
add(n7);
add(n8);
add(n9);
add(n0);
add(point);
add(minus);
add(plus);
add(subtract);
add(multiply);
add(divild);
add(equal);
add(back);
add(ce);
n1.addActionListener(this);
n2.addActionListener(this);
n3.addActionListener(this);
n4.addActionListener(this);
n5.addActionListener(this);
n6.addActionListener(this);
n7.addActionListener(this);
n8.addActionListener(this);
n9.addActionListener(this);
n0.addActionListener(this);
point.addActionListener(this);
minus.addActionListener(this);
plus.addActionListener(this);
subtract.addActionListener(this);
multiply.addActionListener(this);
divild.addActionListener(this);
equal.addActionListener(this);
back.addActionListener(this);
ce.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==n1)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"1";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n2)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"2";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n3)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"3";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n4)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"4";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n5)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"5";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n6)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"6";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n7)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"7";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n8)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"8";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n9)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"9";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==n0)
{
if(biaoji==1){xianshi="";biaoji=0;}
xianshi=xianshi+"0";
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==point)
{if(biaoji==1){xianshi="";biaoji=0;}
if(xianshi.indexOf('.')==-1)
{xianshi=xianshi+".";}
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==minus)
{if(biaoji==1){xianshi="";biaoji=0;}
if(xianshi.indexOf('-')==-1)
{xianshi="-"+xianshi;}
else
{xianshi=xianshi.substring(1,xianshi.length());}
caozuoshu=Float.parseFloat(xianshi);
if(biaoji==-1){jieguo=caozuoshu;biaoji=-1;}
text.setText(xianshi);
}
else if(e.getSource()==plus)
{caozuoshu=0;biaoji=1;yunsuanfu=1;
}
else if(e.getSource()==subtract)
{caozuoshu=0;biaoji=1;yunsuanfu=2;
}
else if(e.getSource()==multiply)
{
caozuoshu=0;biaoji=1;yunsuanfu=3;
}
else if(e.getSource()==divild)
{
caozuoshu=0;biaoji=1;yunsuanfu=4;
}
else if(e.getSource()==equal)
{if(yunsuanfu==1){jieguo=jieguo+caozuoshu;biaoji=1;text.setText(xianshi=String.valueOf(jieguo));}
if(yunsuanfu==2){jieguo=jieguo-caozuoshu;biaoji=1;text.setText(xianshi=String.valueOf(jieguo));}
if(yunsuanfu==3){jieguo=jieguo*caozuoshu;biaoji=1;text.setText(xianshi=String.valueOf(jieguo));}
if(yunsuanfu==4){jieguo=jieguo/caozuoshu;biaoji=1;text.setText(xianshi=String.valueOf(jieguo));}
}
else if(e.getSource()==back)
{
xianshi=xianshi.substring(0,xianshi.length()-1);
caozuoshu=Integer.parseFlaot(xianshi);
text.setText(xianshi);}
else if(e.getSource()==ce)
{
xianshi=new String("");
caozuoshu=0;
jieguo=0;
biaoji=-1;
yunsuanfu=0;
text.setText(xianshi);}