我正在尝试设置setCell方法,但尚未向我提供测试文件中参数的值。 这应该使用'*'字符为我打印一个包含20行30列的框,但它正在为我打印空白行
public Window(final int rows, final int cols, final char border)
{
//Initialize everything
this.rows = rows;
this.cols = cols;
this.border = border;
this.shapes = new ArrayList<Shape>();
this.cells = new char[rows+2][cols+2];
//Make a call to addBorders()
addBorders(border);
}
void setCell(final int row, final int col, final char ch)
{
//set the character at cells[row][col] to 'ch'
cells[row][col]=ch;
}
public void display()
{
for (int i=0; i < rows+2; i++)
{
for(int j=0; j<cols+2; j++)
System.out.print(cells[i][j]);
System.out.println();
}
}
我的测试器文件是=>
public class HouseForSale
{
public static void main(String [] args) throws Exception
{
//Create the window
Window w = new Window(20, 30, '*');
w.display();
}
}
您需要在构造函数(Window)中调用setrCell。如下所示:
public Window(final int rows, final int cols, final char border)
{
//Initialize everything
this.rows = rows;
this.cols = cols;
this.border = border;
this.shapes = new ArrayList<Shape>();
this.cells = new char[rows+2][cols+2];
for (int i=0; i < rows; i++)
for(int j=0; j < cols; j++)
setCell(i,j,ch);
//Make a call to addBorders()
addBorders(border);
}
您永远不会调用setCell。使用您所拥有的内容,您应该像在显示中一样添加一个double for循环,可以类似设置某些单元格或所有单元格都作为边框获得的字符。我不太确定自己我了解您的问题。
for (int i=0; i < rows+2; i++)
{
for(int j=0; j<cols+2; j++)
setCell(i,j,border);
}