我有下面的构造,如果任何三个JButton
S的已经被点击它定义了一个board
和检查:如何访问布尔数组的Java
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
?
你在哪里定义'board'? – 2013-05-14 15:36:14