zoukankan      html  css  js  c++  java
  • demo04calc

    package com.example.demo05simplecalc;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.speech.tts.TextToSpeech;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    
    public class MainActivity extends Activity {
    
        private int no1=0;
        private int no2=0;
    
        private EditText editText1=null;
        private EditText editText2=null;
    
        private Button btnAdd=null;
        private Button btnSub=null;
        private Button btnMul=null;
        private Button btnDiv=null;
    
        private TextView fuhao=null;
        private TextView jieguo=null;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            this.editText1 = (EditText) super.findViewById(R.id.no1);
            this.editText2 = (EditText)super.findViewById(R.id.no2);
    
            this.editText1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    MainActivity.this.editText1.setText("");
                }
            });
    
            this.editText2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    MainActivity.this.editText2.setText("");
                }
            });
    
    
            this.btnAdd = (Button) super.findViewById(R.id.btnAdd);
            this.btnSub = (Button)super.findViewById(R.id.btnSub);
            this.btnMul = (Button)super.findViewById(R.id.btnMul);
            this.btnDiv = (Button)super.findViewById(R.id.btnDel);
    
            this.btnAdd.setOnClickListener(new AddListener());
            this.btnSub.setOnClickListener(new SubListener());
            this.btnMul.setOnClickListener(new MulListener());
            this.btnDiv.setOnClickListener(new DivListener());
    
    
            this.fuhao=(TextView)super.findViewById(R.id.fuhao);
            this.jieguo=(TextView)super.findViewById(R.id.jieguo);
    
    
        }
    
        private class AddListener implements View.OnClickListener {
            @Override
            public void onClick(View view) {
                MainActivity.this.no1 =Integer.parseInt( MainActivity.this.editText1.getText().toString());
                MainActivity.this.no2 =Integer.parseInt( MainActivity.this.editText2.getText().toString());
    
                MainActivity.this.fuhao.setText("+");
                MainActivity.this.jieguo.setText(String.valueOf(no1+no2));
            }
        };
    
        private class SubListener implements View.OnClickListener {
            @Override
            public void onClick(View view) {
                MainActivity.this.no1 =Integer.parseInt( MainActivity.this.editText1.getText().toString());
                MainActivity.this.no2 =Integer.parseInt( MainActivity.this.editText2.getText().toString());
    
                MainActivity.this.fuhao.setText("-");
                MainActivity.this.jieguo.setText(String.valueOf(no1-no2));
            }
        };
    
        private class MulListener implements View.OnClickListener {
            @Override
            public void onClick(View view) {
                MainActivity.this.no1 =Integer.parseInt( MainActivity.this.editText1.getText().toString());
                MainActivity.this.no2 =Integer.parseInt( MainActivity.this.editText2.getText().toString());
    
                MainActivity.this.fuhao.setText("*");
                MainActivity.this.jieguo.setText(String.valueOf(no1*no2));
            }
        };
    
        private class DivListener implements View.OnClickListener {
            @Override
            public void onClick(View view) {
                MainActivity.this.no1 =Integer.parseInt( MainActivity.this.editText1.getText().toString());
                MainActivity.this.no2 =Integer.parseInt( MainActivity.this.editText2.getText().toString());
    
                MainActivity.this.fuhao.setText("/");
                MainActivity.this.jieguo.setText(String.valueOf(no1/no2));
            }
        };
    
    //    @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;
    //    }
        
    }
  • 相关阅读:
    iOS学习6:CoreGraphics简单绘图
    什么是GCD
    iOS对象序列化
    Swift中基本类型的转换
    DataTable转List
    .Net Mvc Automated Migration 数据迁移
    .Net WebApi基本操作
    Sql Server日期时间格式转换
    jquery ajax POST 例子详解
    发布.net mvc遇到的HTTP错误 403.14Forbidden解决办法
  • 原文地址:https://www.cnblogs.com/alamps/p/5236886.html
Copyright © 2011-2022 走看看