PostList

2015년 8월 11일 화요일

계산기

package com.example.han.ex2;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity {

    private static MediaPlayer back;

    EditText edit1, edit2;
    TextView textresult;
    String num1, num2;
    Integer result;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        edit1 = (EditText) findViewById(R.id.textView3);
        edit2 = (EditText) findViewById(R.id.textView4);
        textresult = (TextView) findViewById(R.id.textView5);
            }




    public void btnadd(View v) {
        Toast.makeText(getApplicationContext(), "덧셈", Toast.LENGTH_LONG).show();
        num1 = edit1.getText().toString();
        num2 = edit2.getText().toString();
            if(num1.isEmpty()!= true && num2.isEmpty() !=true) {
               result = Integer.parseInt(num1) + Integer.parseInt(num2);
                textresult.setText("계산결과 : " + result);
            }
        else {textresult.setText("숫자를 입력하시오");}


    }
    public void btnsub(View v){
        Toast.makeText(getApplicationContext(), "뺄셈", Toast.LENGTH_LONG).show();
        num1 = edit1.getText().toString();
        num2 = edit2.getText().toString();
        if(num1.isEmpty()!= true && num2.isEmpty() !=true) {
            result = Integer.parseInt(num1) - Integer.parseInt(num2);
            textresult.setText("계산결과 : " + result.toString());
        }
        else {textresult.setText("숫자를 입력하시오");}
    }

    public void btndiv(View v){
        Toast.makeText(getApplicationContext(), "나눗셈", Toast.LENGTH_LONG).show();
        num1 = edit1.getText().toString();
        num2 = edit2.getText().toString();
        if(num1.isEmpty()!= true && num2.isEmpty() !=true) {
            result = Integer.parseInt(num1) / Integer.parseInt(num2);
            textresult.setText("계산결과 : " + result.toString());
        }
        else {textresult.setText("숫자를 입력하시오");}
    }

    public void btnmul(View v){
        Toast.makeText(getApplicationContext(), "곱셈", Toast.LENGTH_LONG).show();
        num1 = edit1.getText().toString();
        num2 = edit2.getText().toString();
        if(num1.isEmpty()!= true && num2.isEmpty() !=true) {
            result = Integer.parseInt(num1) * Integer.parseInt(num2);
            textresult.setText("계산결과 : " + result.toString());
        }
        else {textresult.setText("숫자를 입력하시오");}

    }
    public void OB4(View v) {
        Toast.makeText(getApplicationContext(), "music start", Toast.LENGTH_LONG).show();
        back=MediaPlayer.create(this, R.raw.ea);
        back.start();
        back.setLooping(true);
    }



    public void OB3(View v) {
        Toast.makeText(getApplicationContext(), "borderlands", Toast.LENGTH_LONG).show();
        back.stop();
    }

    public void button3(View v) {
        Toast.makeText(getApplicationContext(), "종료", Toast.LENGTH_LONG).show();
        finish();
    }




    @Override    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will        // automatically handle clicks on the Home/Up button, so long        // as you specify a parent activity in AndroidManifest.xml.        int id = item.getItemId();

        //noinspection SimplifiableIfStatement        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

댓글 없음:

댓글 쓰기