java程序设计实验报告1(计算器).doc
还剩
18页未读,
继续阅读
下载文档到电脑,马上远离加班熬夜!
亲,喜欢就下载吧,价低环保!
内容要点:
} Double resultMulDouble = resultMul;String s3 = resultMulDouble.toString();if(!isInt(s3))CalculateResult=s3;else {CalculateResult = s3.substring(0,s3.indexOf("."));}break;case '/': if(Double.parseelse if(str.equals("=")){show.setText(CalculateResult);bool = true;}}private boolean isInt(String s) {if(s.indexOf(".")>0){for(int i =(s.length()-1);i>s.indexOf(".");--i){if(!(s.charAt(i)=='0'))returnelse if(str.equals("*")){String show2 = show.getText();show.setText("");ch="*";//保存当前运算符double operate = 0;if(!show2.isEmpty())operate = Double.parseDouble(show2);Div = (Double)operate;}else if(str.eq }else {StringBuffer e = new StringBuffer(result);e.insert(0, "-");show.setText(e.toString());String num = e.toString();if("*-+/".indexOf(ch)>=0){handerResult(ch,num);}}}else if(str.equals("sqrt")if("*-+/".indexOf(ch)>=0){handerResult(ch,num);}}}else {if(result.equals("0")){result=str;show.setText(result);bool = false;String num = result;if("*-+/".indexOf(ch)>=0){handerResult(ch,num);}}else {iprivate void handerMC() {save = "";// TODO Auto-generated method stublabel.setText("");}private void handerMR() {if(!save.isEmpty()){if(!isInt(save))show.setText(save);else {show.setText(save.substrinbool = false;show.setText("0");}else if(str.equals("MC")){//MC 清楚存储器内容handerMC();}else if(str.equals("MR")){//MR 将存于存储器的值显示在文本框中handerMR();}else if(str.equals("MS")){//MS 将显示框得文字存于存储器handerMS();}else }private void addButton(GridBagLayout gridBag,//网格包布布局重要方法;GridBagConstraints constraints, Component component) {gridBag.setConstraints(component, constraints);// TODO Auto-generated method stubtpane
发表评论
暂无评论,赶快抢占沙发吧。