를 액세스하기 위해이 세 가지 JButton
어떤 것인가가 클릭 된 경우 board
및 검사를 정의하는 다음과 같은 생성자 :어떻게 부울 배열 자바
Timer timer = new Timer(500, this);
private boolean[][] board;
private boolean isActive = true;
private int height;
private int width;
private int multiplier = 40;
JButton button1;
JButton button2;
JButton button3;
public Board(boolean[][] board) {
this.board = board;
height = board.length;
width = board[0].length;
setBackground(Color.black);
button1 = new JButton("Stop");
add(button1);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
isActive = !isActive;
button1.setText(isActive ? "Stop" : "Start");
}
});
button2 = new JButton("Random");
add(button2);
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
this.board = randomBoard();
}
});
button3 = new JButton("Clear");
add(button3);
button3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
this.board = clearBoard();
}
});
}
을하지만이 오류가 반환
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
board cannot be resolved or is not a field
board cannot be resolved or is not a field
을
왜 이런가요? 생성자에서 this.board
에 어떻게 액세스합니까?
여기서 '보드'를 정의 했습니까? –