import java.awt.*;
import java.awt.event.*;
import java.lang.*;
class MypanelSouth extends Panel implements ActionListener
{
int f=0;
String flag="none";
String s1="0",s2="0";
TextField text;
Double a=0.0,b=0.0,c=0.0;
String answer="0";
Button button_0,button_1,button_2,button_3,button_4,button_5,button_6,button_7,button_8,
button_9,button_p,button_a,button_m,button_t,button_d,button_e;
MypanelSouth(TextField text)
{
this.text=text;
FlowLayout flow=new FlowLayout();
flow.setAlignment(FlowLayout.LEFT);
flow.setHgap(10);
flow.setVgap(12);
setLayout(flow);
button_0=new Button("0");button_1=new Button("1");button_2=new Button("2"); //添加按钮
button_3=new Button("3");button_4=new Button("4");button_5=new Button("5");
button_6=new Button("6");button_7=new Button("7");button_8=new Button("8");
button_9=new Button("9");button_p=new Button(".");button_a=new Button("+");
button_m=new Button("-");button_t=new Button("*");button_d=new Button("/");button_e=new Button(" = ");
add(button_0);add(button_1);add(button_2);add(button_3);add(button_4);add(button_5);
add(button_6);add(button_7);add(button_8);add(button_9);add(button_p);add(button_a);
add(button_m);add(button_t);add(button_d);add(button_e);
button_0.addActionListener(this);button_1.addActionListener(this); //为每一个按钮增加监视器
button_2.addActionListener(this);button_3.addActionListener(this);
button_4.addActionListener(this);button_5.addActionListener(this);
button_6.addActionListener(this);button_7.addActionListener(this);
button_8.addActionListener(this);button_9.addActionListener(this);
button_p.addActionListener(this);button_a.addActionListener(this);
button_m.addActionListener(this);button_t.addActionListener(this);
button_d.addActionListener(this);button_e.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==button_0) //处理 数字0按钮 的事件
{
if (f==0)
{
s1=s1.concat(button_0.getLabel());
while(s1.regionMatches(0, "0", 0, 1)==true)
{
if (s1.length()>=2&&s1.regionMatches(1, ".", 0, 1)==false)
s1=s1.substring(1);
else
break;
}
text.setText(s1);
}
if (f==1)
{
s2=s2.concat(button_0.getLabel());
while(s2.regionMatches(0, "0", 0, 1)==true)
{
if (s2.length()>=2&&s2.regionMatches(1, ".", 0, 1)==false)
s2=s2.substring(1);
else
break;
}
text.setText(s2);
}
}
if (e.getSource()==button_1) //处理 数字1 的事件
{
if (f==0)
{
s1=s1.concat(button_1.getLabel());
while(s1.regionMatches(0, "0", 0, 1)==true)
{
if (s1.length()>=2&&s1.regionMatches(1, ".", 0, 1)==false)
s1=s1.substring(1);
else
break;
}
text.setText(s1);
}
if (f==1)
{
s2=s2.concat(button_1.getLabel());
while(s2.regionMatches(0, "0", 0, 1)==true)
{
if (s2.length()>=2&&s2.regionMatches(1, ".", 0, 1)==false)
s2=s2.substring(1);
else
break;
}
text.setText(s2);
}
}
if (e.getSource()==button_2) //处理 数字2 的事件
{
if (f==0)
{
s1=s1.concat(button_2.getLabel());
while(s1.regionMatches(0, "0", 0, 1)==true)
{
if (s1.length()>=2&&s1.regionMatches(1, ".", 0, 1)==false)
s1=s1.substring(1);
else
break;
}
text.setText(s1);
}
if (f==1)
{
s2=s2.concat(button_2.getLabel());
while(s2.regionMatches(0, "0", 0, 1)==true)
{
if (s2.length()>=2&&s2.regionMatches(1, ".", 0, 1)==false)
s2=s2.substring(1);
else
break;
}
text.setText(s2);
}
}
if (e.getSource()==button_3) //处理 数字3 的事件
{
if (f==0)
{
s1=s1.concat(button_3.getLabel());
while(s1.regionMatches(0, "0", 0, 1)==true)
{
if (s1.length()>=2&&s1.regionMatches(1, ".", 0, 1)==false)
s1=s1.substring(1);
else
break;
}
text.setText(s1);
}
if (f==1)
{
s2=s2.concat(button_3.getLabel());
while(s2.regionMatches(0, "0", 0, 1)==true)
{
if (s2.length()>=2&&s2.regionMatches(1, ".", 0, 1)==false)
s2=s2.substring(1);
else
break;
}
text.setText(s2);
}
}
if (e.getSource()==button_4) //处理 数字4 的事件
{
if (f==0)
{
s1=s1.concat(button_4.getLabel());
while(s1.regionMatches(0, "0", 0, 1)==true)
{
if (s1.length()>=2&&s1.regionMatches(1, ".", 0, 1)==false)
s1=s1.substring(1);
else
break;
}
text.setText(s1);
}
if (f==1)
{
s2=s2.concat(button_4.getLabel());
while(s2.regionMatches(0, "0", 0, 1)==true)
{
if (s2.length()>=2&&s2.regionMatches(1, ".", 0, 1)==false)
s2=s2.substring(1);
else
break;
}
text.setText(s2);
}
}
if (e.getSource()==button_5) //处理 数字5 的事件
{
if (f==0)
{
s1=s1.concat(button_5.getLabel());
while(s1.regionMatches(0, "0", 0, 1)==true)
{
if (s1.length()>=2&&s1.regionMatches(1, ".", 0, 1)==false)
s1=s1.substring(1);
else
break;
}
text.setText(s1);
}
if (f==1)
{
s2=s2.concat(button_5.getLabel());
while(s2.regionMatches(0, "0", 0, 1)==true)
{
if (s2.length()>=2&&s2.regionMatches(1, ".", 0, 1)==false)
s2=s2.substring(1);
else
break;
}
text.setText(s2);
}
}
if (e.getSource()==button_6) //处理 数字6 的事件
{
if (f==0)
{
s1=s1.concat(button_6.getLabel());
while(s1.regionMatches(0, "0", 0, 1)==true)
{
if (s1.length()>=2&&s1.regionMatches(1, ".", 0, 1)==false)
s1=s1.substring(1);
else
break;
}
text.setText(s1);
}
if (f==1)
{
s2=s2.concat(button_6.getLabel());
while(s2.regionMatches(0, "0", 0, 1)==true)
{
if (s2.length()>=2&&s2.regionMatches(1, ".", 0, 1)==false)
s2=s2.substring(1);
else
break;
}
text.setText(s2);
}
}
if (e.getSource()==button_7) //处理 数字7 的事件
{
if (f==0)
{
s1=s1.concat(button_7.getLabel());
while(s1.regionMatches(0, "0", 0, 1)==true)
{
if (s1.length()>=2&&s1.regionMatches(1, ".", 0, 1)==false)
s1=s1.substring(1);
else
break;
}
text.setText(s1);
}
if (f==1)
{
s2=s2.concat(button_7.getLabel());
while(s2.regionMatches(0, "0", 0, 1)==true)
{
if (s2.length()>=2&&s2.regionMatches(1, ".", 0, 1)==false)
s2=s2.substring(1);
else
break;
}
text.setText(s2);
}
}
if (e.getSource()==button_8) //处理 数字8 的事件
{
if (f==0)
{
s1=s1.concat(button_8.getLabel());
while(s1.regionMatches(0, "0", 0, 1)==true)
{
if (s1.length()>=2&&s1.regionMatches(1, ".", 0, 1)==false)
s1=s1.substring(1);
else
break;
}
text.setText(s1);
}
if (f==1)
{
s2=s2.concat(button_8.getLabel());
while(s2.regionMatches(0, "0", 0, 1)==true)
{
if (s2.length()>=2&&s2.regionMatches(1, ".", 0, 1)==false)
s2=s2.substring(1);
else
break;
}
text.setText(s2);
}
}
if (e.getSource()==button_9) //处理 数字9 的事件
{
if (f==0)
{
s1=s1.concat(button_9.getLabel());
while(s1.regionMatches(0, "0", 0, 1)==true)
{
if (s1.length()>=2&&s1.regionMatches(1, ".", 0, 1)==false)
s1=s1.substring(1);
else
break;
}
text.setText(s1);
}
if (f==1)
{
s2=s2.concat(button_9.getLabel());
while(s2.regionMatches(0, "0", 0, 1)==true)
{
if (s2.length()>=2&&s2.regionMatches(1, ".", 0, 1)==false)
s2=s2.substring(1);
else
break;
}
text.setText(s2);
}
}
if(e.getSource()==button_p) //处理小数点按钮事件
{
if(f==0)
{
s1=s1.concat(button_p.getLabel());
text.setText(s1);
}
if(f==1)
{
s2=s2.concat(button_p.getLabel());
text.setText(s2);
}
}