計算器安卓源代碼_第1頁
計算器安卓源代碼_第2頁
計算器安卓源代碼_第3頁
計算器安卓源代碼_第4頁
計算器安卓源代碼_第5頁
已閱讀5頁,還剩46頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、Java源代碼package com.example.jisuanqi;import java.util.Date;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;public class MainActivity extends Activity private Button one;p

2、rivate Button two;private Button three;private Button four;private Button five;private Button six;private Button seven;private Button eight;private Button nine;private Button zero;private Button dot;private Button add;private Button sub;private Button mult;private Button division;private Button amou

3、nt;private Button clear;private Button time;private Button sqrt;private Button pow;private EditText led;String num1 = ;String num2 = ;double num3 = 0;String rezult = ;String sign = null;int mark = 0;boolean flag = true;boolean dotmark = true;protected void onCreate(Bundle savedInstanceState) super.o

4、nCreate(savedInstanceState);setContentView(R.layout.activity_main);zero = (Button) findViewById(R.id.zero);one = (Button) findViewById(R.id.one);two = (Button) findViewById(R.id.two);three = (Button) findViewById(R.id.three);four = (Button) findViewById(R.id.four);five = (Button) findViewById(R.id.f

5、ive);six = (Button) findViewById(R.id.six);seven = (Button) findViewById(R.id.seven);eight = (Button) findViewById(R.id.eight);nine = (Button) findViewById(R.id.nine);dot = (Button) findViewById(R.id.dot);add = (Button) findViewById(R.id.add);sub = (Button) findViewById(R.id.sub);mult = (Button) fin

6、dViewById(R.id.mult);division = (Button) findViewById(R.id.division);clear = (Button) findViewById(R.id.clear);amount = (Button) findViewById(R.id.amount);time = (Button) findViewById(R.id.time);pow = (Button) findViewById(R.id.pow);sqrt = (Button) findViewById(R.id.sqrt);led = (EditText) findViewBy

7、Id(R.id.led);zero.setOnClickListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1 = num1 + 0;led.setText(num1); else if (mark = 1) num2 = num2 + 0;led.setText(num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 0;led.setText(num1 + sign + num2););one.setOnClic

8、kListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1 = num1 + 1;led.setText(num1); else if (mark = 1) num2 = num2 + 1;led.setText(num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 1;led.setText(num1 + sign + num2););two.setOnClickListener(new OnClickListen

9、er() public void onClick(View v) if (mark = 0) num1 = num1 + 2;led.setText(num1); else if (mark = 1) num2 = num2 + 2;led.setText(num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 2;led.setText(num1 + sign + num2););three.setOnClickListener(new OnClickListener() public void onClick(

10、View v) if (mark = 0) num1 = num1 + 3;led.setText(num1); else if (mark = 1) num2 = num2 + 3;led.setText(num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 3;led.setText(num1 + sign + num2););four.setOnClickListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1

11、 = num1 + 4;led.setText(num1); else if (mark = 1) num2 = num2 + 4;led.setText(num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 4;led.setText(num1 + sign + num2););five.setOnClickListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1 = num1 + 5;led.setText(nu

12、m1); else if (mark = 1) num2 = num2 + 5;led.setText(num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 5;led.setText(num1 + sign + num2););six.setOnClickListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1 = num1 + 6;led.setText(num1); else if (mark = 1) num

13、2 = num2 + 6;led.setText(num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 6;led.setText(num1 + sign + num2););seven.setOnClickListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1 = num1 + 7;led.setText(num1); else if (mark = 1) num2 = num2 + 7;led.setText(

14、num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 7;led.setText(num1 + sign + num2););eight.setOnClickListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1 = num1 + 8;led.setText(num1); else if (mark = 1) num2 = num2 + 8;led.setText(num1 + sign + num2); else

15、 num1 = String.valueOf(num3);num2 = num2 + 8;led.setText(num1 + sign + num2););nine.setOnClickListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1 = num1 + 9;led.setText(num1); else if (mark = 1) num2 = num2 + 9;led.setText(num1 + sign + num2); else num1 = String.valueOf(num

16、3);num2 = num2 + 9;led.setText(num1 + sign + num2););add.setOnClickListener(new OnClickListener() public void onClick(View v) if (flag) sign = +;mark+;flag = false;dotmark = true;);sub.setOnClickListener(new OnClickListener() public void onClick(View v) if (flag) sign = -;mark+;flag = false;dotmark

17、= true;);mult.setOnClickListener(new OnClickListener() public void onClick(View v) if (flag) sign = *;mark+;flag = false;dotmark = true;);division.setOnClickListener(new OnClickListener() public void onClick(View v) if (flag) sign = ;mark+;flag = false;dotmark = true;);pow.setOnClickListener(new OnC

18、lickListener() public void onClick(View v) if (flag) sign = ;mark+;flag = false;dotmark = true;);dot.setOnClickListener(new OnClickListener() public void onClick(View v) if (dotmark) if (mark = 0) num1 = num1 + .;led.setText(num1); else if (mark = 1) num2 = num2 + .;led.setText(num1 + sign + num2);

19、else num1 = String.valueOf(num3);num2 = num2 + .;led.setText(num1 + sign + num2);dotmark = false;);amount.setOnClickListener(new OnClickListener() / 等于時發(fā)生的運算public void onClick(View v) flag = true;dotmark = true;if (sign.equals(+) double x = Double.parseDouble(num1);double y = Double.parseDouble(num

20、2);num3 = x + y;rezult = String.valueOf(num3);led.setText(num1 + sign + num2 + = + rezult);num2 = ; else if (sign.equals(-) double x = Double.parseDouble(num1);double y = Double.parseDouble(num2);num3 = x - y;rezult = String.valueOf(num3);led.setText(num1 + sign + num2 + = + rezult);num2 = ; else if

21、 (sign.equals(*) double x = Double.parseDouble(num1);double y = Double.parseDouble(num2);num3 = x * y;rezult = String.valueOf(num3);led.setText(num1 + sign + num2 + = + rezult);num2 = ; else if (sign.equals() double x = Double.parseDouble(num1);double y = Double.parseDouble(num2);num3 = x / y;rezult = String.valueOf(num3);led.setText(num1 + sign + num2 + = + rezult);num2 = ; else if (sign.equals() double x = Double.parseD

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論