본문 바로가기

실시간 운영체제

[실시간 운영체제] reverse button 3x3 행렬

버튼으로 간단한 reverse 3x3 행렬 코드입니다.

 

package com.example.midterm_problm3;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;

public class MainActivity extends AppCompatActivity {

    private RadioButton rbGroup[][] = new android.widget.RadioButton[3][3];
    private RadioButton RB_00,RB_01,RB_02,RB_10,RB_11,RB_12,RB_20,RB_21,RB_22;

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

        RB_00 = (RadioButton) findViewById(R.id.rb_00);
        RB_01 = (RadioButton) findViewById(R.id.rb_01);
        RB_02 = (RadioButton) findViewById(R.id.rb_02);
        RB_10 = (RadioButton) findViewById(R.id.rb_10);
        RB_11 = (RadioButton) findViewById(R.id.rb_11);
        RB_12 = (RadioButton) findViewById(R.id.rb_12);
        RB_20 = (RadioButton) findViewById(R.id.rb_20);
        RB_21 = (RadioButton) findViewById(R.id.rb_21);
        RB_22 = (RadioButton) findViewById(R.id.rb_22);

        rbGroup [0][0] = RB_00;
        rbGroup [0][1] = RB_01;
        rbGroup [0][2] = RB_02;
        rbGroup [1][0] = RB_10;
        rbGroup [1][1] = RB_11;
        rbGroup [1][2] = RB_12;
        rbGroup [2][0] = RB_20;
        rbGroup [2][1] = RB_21;
        rbGroup [2][2] = RB_22;
    }

    public void click_1(View view){

        for (int i=0;i<3;i++){
                if(rbGroup[i][0].isChecked()){
                    rbGroup[i][0].setChecked(false);
                }
                else {
                    rbGroup[i][0].setChecked(true);
                }
        }
    }

    public void click_2(View view){

        for (int i=0;i<3;i++){
            if(rbGroup[i][1].isChecked()){
                rbGroup[i][1].setChecked(false);
            }
            else{
                rbGroup[i][1].setChecked(true);
            }
        }
    }

    public void click_3(View view){

        for (int i=0;i<3;i++){
            if(rbGroup[i][2].isChecked()){
                rbGroup[i][2].setChecked(false);
            }
            else{
                rbGroup[i][2].setChecked(true);
            }
        }
    }

    public void click_4(View view){

        for (int j=0;j<3;j++) {

            if (rbGroup[2][j].isChecked()) {
                rbGroup[2][j].setChecked(false);
            } else {
                rbGroup[2][j].setChecked(true);
            }
        }
    }

    public void click_5(View view){

        for (int j=0;j<3;j++){
            if(rbGroup[1][j].isChecked()){
                rbGroup[1][j].setChecked(false);
            }
            else{
                rbGroup[1][j].setChecked(true);
            }
        }
    }

    public void click_6(View view){

        for (int j=0;j<3;j++){
            if(rbGroup[0][j].isChecked()){
                rbGroup[0][j].setChecked(false);
            }
            else{
                rbGroup[0][j].setChecked(true);
            }
        }
    }
}