首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2ME开发 >

,救急帮帮小弟我吧!拜托

2011-12-21 
各位高手,救急~帮帮我吧!拜托~这是用JAVA编写的计算器中的一段程序,麻烦各位高手帮帮我,下面这段程序是什

各位高手,救急~帮帮我吧!拜托~
这是用JAVA编写的计算器中的一段程序,麻烦各位高手帮帮我,下面这段程序是什么功能?拜托~
程序如下:
if(this.keyAvailable && e.getActionCommand().length()==1 && e.getActionCommand().compareTo("0")>=0 && e.getActionCommand().compareTo("9")<=0)
{
if(this.isTempNowInput)
{
this.dNowInput=0;
this.isTempNowInput=false;
}
this.nBitsNum++;
if(this.alreadyHaveDot==false)
this.dNowInput=this.dNowInput*10+Double.parseDouble(e.getActionCommand());
else
{
double temp=Double.parseDouble(e.getActionCommand());
for(int i=this.n;i<0;i++)
{
temp*=0.1;
}
this.dNowInput+=temp;
this.n--;
}
this.tf1.setText(Double.toString(this.dNowInput));
}
// key dot
if(this.keyAvailable && e.getActionCommand()==".")
{
if(this.alreadyHaveDot==false)
{
this.nBitsNum++;
this.alreadyHaveDot=true;
this.n=-1;
}
}
//key "+","-","*","/"
if(this.keyAvailable && e.getActionCommand()=="+" || e.getActionCommand()=="-" || e.getActionCommand()=="*" || e.getActionCommand()=="/")
{
if(this.alreadyClickedEqueal)
{
this.dNowInput=this.dResult;
this.isTempNowInput=true;
}
else
{
switch(this.nOperation)
{
case 1: this.dResult+=this.dNowInput; break;
case 2: this.dResult-=this.dNowInput; break;
case 3: this.dResult*=this.dNowInput; break;
case 4:
{
if(this.dNowInput==0)
{
tf1.setText("除数不能为零");
this.keyAvailable=false;
}
else this.dResult=this.dResult/this.dNowInput;
}
}
if(this.keyAvailable)tf1.setText(Double.toString(this.dResult));
this.dNowInput=0;
}
if(e.getActionCommand()=="+")
{
this.nOperation=1;
}
if(e.getActionCommand()=="-")
{
this.nOperation=2;
}
if(e.getActionCommand()=="*")
{
this.nOperation=3;
}
if(e.getActionCommand()=="/")
{
this.nOperation=4;
}
this.nBitsNum=0;
this.alreadyClickedEqueal=false;
}
// key "+/-"
if(this.keyAvailable && e.getActionCommand()=="+/-")
{
this.dNowInput=0-this.dNowInput;
tf1.setText(Double.toString(this.dNowInput));
}
// key "C"
if(e.getActionCommand()=="C")
{
this.nBitsNum=0;
this.dResult=0;
this.dNowInput=0;
this.alreadyHaveDot=false;
this.n=0;
this.nOperation=1;
this.keyAvailable=true;
this.alreadyClickedEqueal=false;
tf1.setText("0.");
}
// key "CE"
if(e.getActionCommand()=="CE")
{
this.nBitsNum=0;
this.dNowInput=0;
this.alreadyHaveDot=false;
this.n=0;
this.nOperation=1;
this.keyAvailable=true;
tf1.setText("0.");
}

// key "sqrt"
if(this.keyAvailable && e.getActionCommand()=="sqrt")
{
if(this.alreadyClickedEqueal)
{
if(this.dResult>=0)
{
this.dResult=Math.sqrt(this.dResult);
tf1.setText(Double.toString(this.dResult));
}
else
{
tf1.setText("函数输入无效");
this.keyAvailable=false;
}
}
else
{
if(this.dNowInput>=0)
{
this.dNowInput=Math.sqrt(this.dNowInput);
tf1.setText(Double.toString(this.dNowInput));
}
else


{
tf1.setText("函数输入无效");
this.keyAvailable=false;
}
}
}
// key "1/x"
if(this.keyAvailable && e.getActionCommand()=="1/x")
{
if(this.dNowInput==0)
{
tf1.setText("除数不能为零");
this.keyAvailable=false;
}
else
{
this.dNowInput=1/this.dNowInput;
tf1.setText(Double.toString(this.dNowInput));
}
}
// key "="
if(this.keyAvailable && e.getActionCommand()=="=")
{
this.alreadyClickedEqueal=true;
switch(this.nOperation)
{
case 1: this.dResult+=this.dNowInput; break;
case 2: this.dResult-=this.dNowInput; break;
case 3: this.dResult*=this.dNowInput; break;
case 4:
{
if(this.dNowInput==0)
{
tf1.setText("除数不能为零");
this.keyAvailable=false;
}
else this.dResult=this.dResult/this.dNowInput;
}
}
if(this.keyAvailable)tf1.setText(Double.toString(this.dResult));
}
// key "MS"
if(this.keyAvailable && e.getActionCommand()=="MS")
{
this.dMemory=this.dNowInput;
if(this.dMemory!=0)
tf2.setText("M");
}
// key "MC"
if(this.keyAvailable && e.getActionCommand()=="MC")
{
this.dMemory=0;
tf2.setText("");
}
// key "MR"
if(this.keyAvailable && e.getActionCommand()=="MR")
{
this.dNowInput=this.dMemory;
tf1.setText(Double.toString(this.dNowInput));
}
// key "M+"
if(this.keyAvailable && e.getActionCommand()=="M+")
{
this.dMemory+=this.dNowInput;
if(this.dMemory!=0)
tf2.setText("M");
else tf2.setText("");
}
// key "%"
if(this.keyAvailable && e.getActionCommand()=="%")
{
this.dNowInput=(this.dResult*this.dNowInput)/100;
tf1.setText(Double.toString(this.dNowInput));
}
// key "Backspace"
if(this.keyAvailable && e.getActionCommand()=="Backspace")
{
if(!this.alreadyClickedEqueal){
if(this.dNowInput!=0)
{
if(this.alreadyHaveDot)
{
if(this.n==-1)
{
this.alreadyHaveDot=false;
this.n=0;
}
else
{
String str,str1;
str=tf1.getText();
str1=str.substring(0,this.nBitsNum-1);
this.nBitsNum--;
this.n++;
this.dNowInput=Double.parseDouble(str1);
tf1.setText(Double.toString(this.dNowInput));
}
}
else
{
int temp;
temp=(int)(this.dNowInput/10);
this.dNowInput=(double)temp;
tf1.setText(Double.toString(this.dNowInput));
}
}
}
}
}

[解决办法]
帮楼主顶下
[解决办法]
认真看嘛,又不是很难,看了前面一小段,第一个if意思是响应0-9键的输入,分有无小数点的情况。第二个if是响应小数点的按键事件。下面都以此类推了。

热点排行