package com.example.theater;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText row,col;
Button btn1;
TextView textResult;
int[][] seat, board;
int i,j,pax;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
row = findViewById(R.id.row);
col = findViewById(R.id.col);
btn1 = findViewById(R.id.btn1);
textResult = findViewById(R.id.textResult);
i = Integer.parseInt(row.getText().toString());
j = Integer.parseInt(col.getText().toString());
pax=25;
board = new seat[5][5];
int[][]boardId={{R.id.seat11, R.id.seat12, R.id.seat13, R.id.seat14, R.id.seat15},
{R.id.seat21, R.id.seat22, R.id.seat23, R.id.seat24, R.id.seat25},
{R.id.seat31, R.id.seat32, R.id.seat33, R.id.seat34, R.id.seat35},
{R.id.seat41, R.id.seat42, R.id.seat43, R.id.seat44, R.id.seat45},
{R.id.seat51, R.id.seat52, R.id.seat53, R.id.seat54, R.id.seat55}};
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
this.board[i][j] = (seat) findViewById(boardId[i][j]);
}
}
btn1.setOnClickListener(v -> {
while (pax > 0) {
if ((j > 5 || j < 1) || (i > 5 || i < 1)) {
Toast.makeText(getApplicationContext(), "잘못된 입력입니다. 다시 입력하세요.", Toast.LENGTH_LONG).show();
continue;
}
if (seat[j - 1][i - 1] == 0) {
board[i][j].setBackgroundColor(Color.parseColor("#FF0000"));
seat[j - 1][i - 1] = 1;
} else {
Toast.makeText(getApplicationContext(), "예약이 완료된 자리입니다. 다시 예약하세요.", Toast.LENGTH_LONG).show();
}
}
}
);
}}
이제 막 배우기 시작한 초보라 많이 부족합니다 ㅠㅠ...
2차원배열로 행이랑 열을 입력받아 좌석예약되면 해당좌석 색을 바꾸고 싶은데...
31열에 cannot resolved symbol 'seat'
53열에 Cannot resolve method 'setBackgroundColor(int)'
이렇게 나옵니다... 뭐가 문젠지 감도안오네요...도와주세요 ㅠㅠ....