package com.example.cal;


import android.R.integer;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.ImageButton;


public class MainActivity extends Activity {

private ImageButton one ,two, three ,four,five,six,seven,eight,nine,zero,add,

dividion,equal,minus,product;

EditText et;

String num,backnum,allnum;

int i,backi,alli;

int logo;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

et=(EditText) findViewById(R.id.et_num);

zero=(ImageButton) findViewById(R.id.ib_0);

one=(ImageButton) findViewById(R.id.ib_1);

two=(ImageButton) findViewById(R.id.ib_2);

three=(ImageButton) findViewById(R.id.ib_3);

four=(ImageButton) findViewById(R.id.ib_4);

five=(ImageButton) findViewById(R.id.ib_5);

six=(ImageButton) findViewById(R.id.ib_6);

seven=(ImageButton) findViewById(R.id.ib_7);

eight=(ImageButton) findViewById(R.id.ib_8);

nine=(ImageButton) findViewById(R.id.ib_9);

add=(ImageButton) findViewById(R.id.loga_add);

dividion=(ImageButton) findViewById(R.id.dividion);

minus=(ImageButton) findViewById(R.id.minus);

product=(ImageButton) findViewById(R.id.pro);

equal=(ImageButton) findViewById(R.id.equal);

}

// public void init(){

// et=(EditText) findViewById(R.id.et_num);

// zero=(Button) findViewById(R.id.ib_0);

// one=(Button) findViewById(R.id.ib_1);

// two=(Button) findViewById(R.id.ib_2);

// three=(Button) findViewById(R.id.ib_3);

// four=(Button) findViewById(R.id.ib_4);

// five=(Button) findViewById(R.id.ib_5);

// six=(Button) findViewById(R.id.ib_6);

// seven=(Button) findViewById(R.id.ib_7);

// eight=(Button) findViewById(R.id.ib_8);

// nine=(Button) findViewById(R.id.ib_9);

// add=(Button) findViewById(R.id.loga_add);

// dividion=(Button) findViewById(R.id.dividion);

// minus=(Button) findViewById(R.id.minus);

// product=(Button) findViewById(R.id.pro);

// equal=(Button) findViewById(R.id.equal);

// }

public void one(View v){

et.append("1");

}

public void two(View v){

et.append("2");

}

public void three(View v){

et.append("3");

}

public void four(View v){

et.append("4");

}

public void five(View v){

et.append("5");

}

public void six(View v){

et.append("6");

}

public void seven(View v){

et.append("7");

}

public void eight(View v){

et.append("8");

}

public void nine(View v){

et.append("9");

}

public void zero(View v){

et.append("0");

}

//当点击加号

public void add(View v){

num=et.getText().toString();

if(num.equals("")){

et.setText("");

}else{

i = Integer.parseInt(num);

logo=1;

 


et.setText("");}

}

//当点击减号

public void minus(View v){

num=et.getText().toString();

if(num.equals("")){

et.setText("");

}else{

i=Integer.parseInt(num);

logo=2;

et.setText("");}

}

//当点击乘号

public void product(View v){

num=et.getText().toString();

if(num.equals("")){

et.setText("");

}else{

i=Integer.parseInt(num);

logo=3;

et.setText("");}

}

//当点击除号

public void dividion(View v){

num=et.getText().toString();

if(num.equals("")){

et.setText("");

}else{

i=Integer.parseInt(num);

logo=4;

et.setText("");}

}

public void back(View v){

num=et.getText().toString();

if(num.equals("")){

et.setText("");

}else{

String mnum=num.substring(0, num.length()-1);

et.setText(mnum);}

}

//当点击等号

public void equal(View v){

backnum=et.getText().toString();

if(backnum.equals("")){

et.setText("");

}else{

backi=Integer.parseInt(backnum);

if(logo==1){

alli=i+backi;

backnum=Integer.toString(alli);

et.setText(backnum);

}else if(logo==2){

alli=i-backi;

backnum=Integer.toString(alli);

et.setText(backnum);

}else if(logo==3){

alli=i*backi;

backnum=Integer.toString(alli);

et.setText(backnum);

}else{

alli=i/backi;

backnum=Double.toString(alli);

et.setText(backnum);

}}

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}


}