我正在编写一个代码,它根据原始颜色将数组单元格的颜色更改为黑色或白色。如果单元格为白色,则变为黑色,反之亦然。我正在使用以下代码:
public class Grid {
boolean[][] grid;
private int Height;
private int Width;
public White;
public Black;
public Grid(int height, int width) {
Height = height;
Width = width;
}
public int getHeight() {
return Height;
}
public int getWidth() {
return Width;
}
public boolean isWhite(int i, int j) {
boolean [][] Grid = new boolean [Height][Width];
for ( i = 0; i<Height ; i++);{
for (j = 0; j<Width ; j++){
if (Grid[i][j] ?? //iswhite) {
??//setBlack
}
else (??)//setWhite
}
}
}}
protected void setWhite(int i, int j) {
??
}
protected void setBlack(int i, int j) {
??
}
}
我相信我应该根据布尔值为 Grid[i][j] 创建一个实例,但是我不确定如何将“public boolean isWhite”与“setWhite”和“setBlack”联系起来。我应该怎么做?