zoukankan      html  css  js  c++  java
  • Android开发简单计算器

    界面如图

    image

    src/Ex03_16.java

    package gphone.EX03_16;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    
    public class EX03_16 extends Activity {
    	EditText et1=null;
    	EditText et2=null;
    	Button btnJia=null;
    	Button btnJian=null;
    	Button btnCheng=null;
    	Button btnChu=null;
    	TextView tvFH=null;
    	TextView tvResult=null;
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            et1=(EditText)findViewById(R.id.et1);
            et2=(EditText)findViewById(R.id.et2);
            btnJia=(Button)findViewById(R.id.btnJia);
            btnJian=(Button)findViewById(R.id.btnJian);
            btnCheng=(Button)findViewById(R.id.btnCheng);
            btnChu=(Button)findViewById(R.id.btnChu);
            tvFH=(TextView)findViewById(R.id.tvFH);
            tvResult=(TextView)findViewById(R.id.tvResult);
           //加
            btnJia.setOnClickListener(new Button.OnClickListener(){
    
    			@Override
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				tvFH.setText(btnJia.getText());
    			    tvResult.setText(Integer.toString(Integer.parseInt(et1.getText().toString())+Integer.parseInt(et2.getText().toString())));
    			}
            	
            });
            //减
            btnJian.setOnClickListener(new Button.OnClickListener(){
    
    			@Override
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				tvFH.setText(btnJian.getText());
    			    tvResult.setText(Integer.toString(Integer.parseInt(et1.getText().toString())-Integer.parseInt(et2.getText().toString())));
    			}
            	
            });
            //乘以
            btnCheng.setOnClickListener(new Button.OnClickListener(){
    
    			@Override
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				tvFH.setText(btnCheng.getText());
    			    tvResult.setText(Integer.toString(Integer.parseInt(et1.getText().toString())*Integer.parseInt(et2.getText().toString())));
    			}
            	
            });
            //除以
            btnChu.setOnClickListener(new Button.OnClickListener(){
    
    			@Override
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				tvFH.setText(btnChu.getText());
    			    tvResult.setText(Integer.toString(Integer.parseInt(et1.getText().toString())/Integer.parseInt(et2.getText().toString())));
    			}
            	
            });
        }
    }

    运行结果

    image

  • 相关阅读:
    2013年 积木大赛
    Matlab 画图2
    Matlab 画图1
    Matlab 数值计算
    Matlab 条件循环函数
    Non Super Boring Substring 题解(hash+思维)
    Matlab 数组
    Matlab 矩阵
    L
    hdu 1671Phone List
  • 原文地址:https://www.cnblogs.com/AlexCheng/p/2120039.html
Copyright © 2011-2022 走看看