[XML]簡單計算器源碼

來源:本網整理

#設置apache自啟動點擊(此處)折疊或打開chmod 700/etc/init.d/httpdetc/init.d/httpd startsbin/chkconfig-add httpdsbin/chkconfig-level 2345 httpd oncd./Install PHP 5.4.0 ===============#編譯安裝相關支持庫cd/opttar-zxvf libiconv-1.14.tar.gzcd libiconv-1.14/configuremake;make installcd./tar-jxvf libmcrypt-2.5.8.tar.bz2cd libmcrypt-2.5.8/configuremake;make installsbin/ldconfigcd libltdl/configure-enable-ltdl-installmake;make installcd/opttar-jxvf mhash-0.9.9.9.tar.bz2cd mhash-0.9.9.9/configuremake;make installln-s/usr/local/lib/libmcrypt.la/usr/lib/libmcrypt.laln-s/usr/local/lib/libmcrypt.so/usr/lib/libmcrypt.soln-s/usr/local/lib/libmcrypt.so.4/usr/lib/libmcrypt.so.4ln-s/usr/local/lib/libmcrypt.so.4.4.8/usr/lib/libmcrypt.so.4.4.8ln-s/usr/local/lib/libmhash.a/usr/lib/libmhash.aln-s/usr/local/lib/libmhash.la/usr/lib/libmhash.laln-s/usr/local/lib/libmhash.so/usr/lib/libmhash.soln-s/usr/local/lib/libmhash.so.2/usr/lib/libmhash.so.2ln-s/usr/local/lib/libmhash.so.2.0.1/usr/lib/libmhash.so.2.0.1cd/opttar-zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8/sbin/ldconfigconfiguremake;make installwww.13333515.buzz防采集請勿采集本網。

使用imag.js開發的簡單計算器原生app scrolltotop.offset(100,120); scrolltotop.init();

[1].[圖片] 計算??70 480.png 跳至 [1] [2] [3] [4] [5]

[2].[代碼] 布局代碼 跳至[1] [2] [3] [4] [5]

<grid cols="5"> <item style="padding-bottom:20" onclick="command(7)"><label style="font-size:30">7</label></item> <item style="padding-bottom:20" onclick="command(8)"><label style="font-size:30">8</label></item> <item style="padding-bottom:20" onclick="command(9)"><label style="font-size:30">9</label></item> <item style="padding-bottom:20" onclick="del()"><label style="font-size:30">??lt;/label></item> <item style="padding-bottom:20" onclick="clearscreen()"><label style="font-size:30">C</label></item> <item style="padding-bottom:20" onclick="command(4)"><label style="font-size:30">4</label></item> <item style="padding-bottom:20" onclick="command(5)"><label style="font-size:30">5</label></item> <item style="padding-bottom:20" onclick="command(6)"><label style="font-size:30">6</label></item> <item style="padding-bottom:20" onclick="times()"><label style="font-size:30">x</label></item> <item style="padding-bottom:20" onclick="divide()"><label style="font-size:30">/</label></item> <item style="padding-bottom:20" onclick="command(1)"><label style="font-size:30">1</label></item> <item style="padding-bottom:20" onclick="command(2)"><label style="font-size:30">2</label></item> <item style="padding-bottom:20" onclick="command(3)"><label style="font-size:30">3</label></item> <item style="padding-bottom:20" onclick="plus()"><label style="font-size:30">+</label></item> <item style="padding-bottom:20" onclick="minus()"><label style="font-size:30">-</label></item> <item style="padding-bottom:20" onclick="command(0)"><label style="font-size:30">0</label></item> <item style="padding-bottom:20" onclick="dzero()"><label style="font-size:30">00</label></item> <item style="padding-bottom:20" onclick="dot()"><label style="font-size:30">.</label></item> <item style="padding-bottom:20" onclick="persent()"><label style="font-size:30">%</label></item> <item style="padding-bottom:20;background:#4bae50,#13a4af" onclick="equal()"><label style="font-size:30;color:#ffffff">=</label></item></grid>

[3].[代碼] js核心代碼 跳至[1] [2] [3] [4] [5]

http://wenku.baidu.com/view/5cfcb42d2af90242a895e5f6.html

<script> <![CDATA[ var num=0,result=0,numshow="0"; var operate=0; //判斷輸入狀態的標志 var calcul=0; //判斷計算狀態的標志 var quit=0; //防止重復按鍵的標?? var ScreenValue = $('numScreen').value; function refresh_Screen(){ $('numScreen').value = ScreenValue;//刷新顯示 } function command(num){ var str=ScreenValue; //獲得當前顯示數據 if(str!='0'&&operate==0){ str = str; }else { str = ''; }//如果當前值不??0",且狀態為0,則返回當前值,否則返回空?? str=str + String(num);//給當前值追加字?? ScreenValue=str; refresh_Screen();//刷新顯示 operate=0; //重置輸入狀?? quit=0; //重置防止重復按鍵的標?? } function dzero(){ var str=ScreenValue; if(str!='0'&&operate==0){ str = str + '00'; }else { str = '0'; }//如果當前值不??0",且狀態為0,則返回當str+"00",否則返??0"; ScreenValue=str; refresh_Screen(); operate=0; } function dot(){ var str=ScreenValue; if(str!='0'&&operate==0){ str = str; }else { str = '0'; }//如果當前值不??0",且狀態為0,則返回當前值,否則返回"0"; for(i=0; i<=str.length;i++){ //判斷是否已經有一個點?? if(str.substr(i,1)==".") return false; //如果有則不再插入 } str=str + "."; ScreenValue=str; refresh_Screen(); operate=0; } function del(){ //退?? var str=ScreenValue; str=str.substr(0,str.length-1); ScreenValue=str; refresh_Screen(); } function clearscreen(){ //清除數據 num=0; result=0; numshow="0"; ScreenValue="0"; refresh_Screen(); } function plus(){ //加法 calculate(); //調用計算函數 operate=1; //更改輸入狀?? calcul=1; //更改計算狀態為?? } function minus(){ //減法 calculate(); operate=1; calcul=2; } function times(){ //乘法 calculate(); operate=1; calcul=3; } function divide(){ //除法 calculate(); operate=1; calcul=4; } function persent(){ //求余 calculate(); operate=1; calcul=5; } function equal(){ calculate(); //等于 operate=1; num=0; result=0; numshow="0"; } // function calculate(){ numshow=Number(ScreenValue); if(num!=0 && quit!=1){ //判斷前一個運算數是否為零以及防重復按鍵的狀?? switch(calcul){ //判斷要輸入狀?? case 1:result=num+numshow;break; //計算"+" case 2:result=num-numshow;break; //計算"-" case 3:result=num*numshow;break; case 4:if(numshow!=0){result=num/numshow;}else{hint("被除數不能為??")} break; case 5:result=num%numshow;break; } quit=1; //避免重復按鍵 } else{ result=numshow; } numshow=String(result); ScreenValue=numshow; refresh_Screen(); num=result; //存儲當前?? } ]]></script>

[4].[代碼] 完整代碼壓縮?? 跳至[1] [2] [3] [4] [5]

把代碼貼出來讓大伙看看,就知道了

下載完壓縮包后可直接導入到在愛碼哥云端平臺上創建的應用中

[5].[文件] calculator.rar ~ 3KB    (3) 跳至 [1] [2] [3] [4] [5]

文件不存在或者代碼語言不存??/div> SyntaxHighlighter.autoloader( 'applescript/js/sh309/scripts/shBrushAppleScript.js?t=1451961936000', 'actionscript3 as3/js/sh309/scripts/shBrushAS3.js?t=1451961936000', 'bash shell/js/sh309/scripts/shBrushBash.js?t=1451961936000', 'coldfusion cf/js/sh309/scripts/shBrushColdFusion.js?t=1451961936000', 'cpp c/js/sh309/scripts/shBrushCpp.js?t=1451961936000', 'obj-c objc/js/sh309/scripts/shBrushObjC.js?t=1451961936000', 'c# c-sharp csharp/js/sh309/scripts/shBrushCSharp.js?t=1451961936000', 'css/js/sh309/scripts/shBrushCss.js?t=1451961936000', 'delphi pascal/js/sh309/scripts/shBrushDelphi.js?t=1451961936000', 'diff patch pas/js/sh309/scripts/shBrushDiff.js?t=1451961936000', 'erl erlang/js/sh309/scripts/shBrushErlang.js?t=1451961936000', 'groovy/js/sh309/scripts/shBrushGroovy.js?t=1451961936000', 'haxe hx/js/sh309/scripts/shBrushHaxe.js?t=1451961936000', 'java/js/sh309/scripts/shBrushJava.js?t=1451961936000', 'jfx javafx/js/sh309/scripts/shBrushJavaFX.js?t=1451961936000', 'js jscript javascript/js/sh309/scripts/shBrushJScript.js?t=1451961936000', 'perl pl/js/sh309/scripts/shBrushPerl.js?t=1451961936000', 'php/js/sh309/scripts/shBrushPhp.js?t=1451961936000', 'text plain/js/sh309/scripts/shBrushPlain.js?t=1451961936000', 'py python/js/sh309/scripts/shBrushPython.js?t=1451961936000', 'ruby rails ror rb/js/sh309/scripts/shBrushRuby.js?t=1451961936000', 'scala/js/sh309/scripts/shBrushScala.js?t=1451961936000', 'sql/js/sh309/scripts/shBrushSql.js?t=1451961936000', 'vb vbnet/js/sh309/scripts/shBrushVb.js?t=1451961936000', 'xml xhtml xslt html/js/sh309/scripts/shBrushXml.js?t=1451961936000' ); SyntaxHighlighter.all();

不好意思,有感而發占用了你這么多空間,不管怎么說,你的水平不用看你所說的計算器,從你完成計算器這件事和你的這個提問本身就能看出來了,因為一個完整的計算器算法會涉及很多原始的數據結構設計思想和

下面是效果展示:復制代碼代碼如下:xml version="1.0"encoding="utf-8?android:layout_width="match_parentandroid:layout_height="match_parentandroid:orientation="vertical">android:layout_height="wrap_content">android:id="@id/tvResultandroid:layout_width="fill_parentandroid:layout_height="wrap_contentandroid:height="50dpandroid:text="@string/tvResultandroid:layout_height="wrap_content">android:id="@id/btnBackspaceandroid:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:width="150dpandroid:layout_marginLeft="10dpandroid:text="@string/btnbackspace"/>android:id="@id/btnCEandroid:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:width="150dpandroid:text="@string/btnCE"/>android:layout_height="wrap_content">android:id="@id/btn7android:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:layout_marginLeft="10dpandroid:width="75dpandroid:text="@string/btn7"/>android:id="@id/btn8android:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:width="75dpandroid:text="@string/btn8"/>android:id="@id/btn9android:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:width="75dpandroid:text="@string/btn9"/>android:id="@id/btnDivandroid:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:width="75dpandroid:text="@string/btnDiv"/>android:layout_height="wrap_content">android:id="@id/btn4android:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:layout_marginLeft="10dpandroid:width="75dpandroid:text="@string/btn4"/>android:id="@id/btn5android:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:width="75dpandroid:text="@string/btn5"/>android:id="@id/btn6android:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:width="75dpandroid:text="@string/btn6"/>android:id="@id/btnMulandroid:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:width="75dpandroid:text="@string/btnMul"/>android:layout_height="wrap_content">android:id="@id/btn1android:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:layout_marginLeft="10dpandroid:width="75dpandroid:text="@string/btn1"/>android:id="@id/btn2android:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:width="75dpandroid:text="@string/btn2"/>android:id="@id/btn3android:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:width="75dpandroid:text="@string/btn3"/>android:id="@id/btnAddandroid:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:width="75dpandroid:text="@string/btnAdd"/>android:layout_height="wrap_content">android:id="@id/btn0android:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:layout_marginLeft="10dpandroid:width="75dpandroid:text="@string/btn0"/>android:id="@id/btnCandroid:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:width="75dpandroid:text="@string/btnC"/>android:id="@id/btnEquandroid:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:width="75dpandroid:text="@string/btnEqu"/>android:id="@id/btnSubandroid:layout_width="wrap_contentandroid:layout_height="wrap_contentandroid:width="75dpandroid:text="@string/btnSub"/>復制代碼代碼如下:packagecom.example.week2;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;import android.app.Activity;public class MainActivity extends Activity implements OnClickListener{聲明一些控件Button btn0=null;Button btn1=null;Button btn2=null;Button btn3=null;Button btn4=null;Button btn5=null;Button btn6=null;Button btn7=null;Button btn8=null;Button btn9=null;Button btnBackspace=null;Button btnCE=null;Button btnC=null;Button btnAdd=null;Button btnSub=null;Button btnMul=null;Button btnDiv=null;Button btnEqu=null;TextView tvResult=null;聲明兩個參數。接收tvResult前后的值double num1=0,num2=0;double Result=0;計算結果int op=0;判斷操作數,boolean isClickEqu=false;判斷是否按了“=”按鈕Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);從布局文件中獲取控件,btn0=(Button)findViewById(R.id.btn0);btn1=(Button)findViewById(R.id.btn1);btn2=(Button)findViewById(R.id.btn2);btn3=(Button)findViewById(R.id.btn3);btn4=(Button)findViewById(R.id.btn4);btn5=(Button)findViewById(R.id.btn5);btn6=(Button)findViewById(R.id.btn6);btn7=(Button)findViewById(R.id.btn7);btn8=(Button)findViewById(R.id.btn8);btn9=(Button)findViewById(R.id.btn9);btnBackspace=(Button)findViewById(R.id.btnBackspace);btnCE=(Button)findViewById(R.id.btnCE);btnC=(Button)findViewById(R.id.btnC);btnEqu=(Button)findViewById(R.id.btnEqu);btnAdd=(Button)findViewById(R.id.btnAdd);btnSub=(Button)findViewById(R.id.btnSub);btnMul=(Button)findViewById(R.id.btnMul);btnDiv=(Button)findViewById(R.id.btnDiv);tvResult=(TextView)findViewById(R.id.tvResult);添加監聽\\btnBackspace.setOnClickListener(this);btnCE.setOnClickListener(this);btn0.setOnClickListener(this);btn1.setOnClickListener(this);btn2.setOnClickListener(this);btn3.setOnClickListener(this);btn4.setOnClickListener(this);btn5.setOnClickListener(this);btn6.setOnClickListener(this);btn7.setOnClickListener(this);btn8.setOnClickListener(this);btn9.setOnClickListener(this);btnAdd.setOnClickListener(this);btnSub.setOnClickListener(this);btnMul.setOnClickListener(this);btnDiv.setOnClickListener(this);btnEqu.setOnClickListener(this);}Overridepublic void onClick(View v){switch(v.getId()){btnBackspace和CE-case R.id.btnBackspace:String myStr=tvResult.getText().toString();try {tvResult.setText(myStr.substring(0,myStr.length()-1));} catch(Exception e){tvResult.setText("");}break;case R.id.btnCE:tvResult.setText(null);break;btn0-9-case R.id.btn0:if(isClickEqu){tvResult.setText(null);isClickEqu=false;}String myString=tvResult.getText().toString();myString+"0;tvResult.setText(myString);break;case R.id.btn1:if(isClickEqu){tvResult.setText(null);isClickEqu=false;}String myString1=tvResult.getText().toString();myString1+"1;tvResult.setText(myString1);break;case R.id.btn2:if(isClickEqu){tvResult.setText(null);isClickEqu=false;}String myString2=tvResult.getText().toString();myString2+"2;tvResult.setText(myString2);break;case R.id.btn3:if(isClickEqu){tvResult.setText(null);isClickEqu=false;}String myString3=tvResult.getText().toString();myString3+"3;tvResult.setText(myString3);break;cas內容來自www.13333515.buzz請勿采集。

免責聲明 - 關于我們 - 聯系我們 - 廣告聯系 - 友情鏈接 - 幫助中心 - 頻道導航
Copyright © 2017 www.13333515.buzz All Rights Reserved
3排列五开奖结果