a を定義し、3 つの s のいずれかがクリックされboard
たかどうかをチェックする次のコンストラクターがあります。JButton
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
コンストラクタでアクセスするにはどうすればよいですか?