我正在使用一个简单的棋盘程序,它运行良好,但它非常小。我尝试使用 acm.graphics.setsize 方法来调整窗口大小,但在我放置图形对象之前它不会调整大小。我是否需要做一些事情来“刷新”对程序的更改以使其正常工作?
谢谢
/* File CheckerBoard.java
* ----------------------
* This program creates a checkerboard
*/
import acm.graphics.*;
import acm.program.*;
/* This class draws a checkerboard on the graphics window.
* The size of the checkerboard is determined by the
* constants NROWS and NCOLUMNS, and the checkerboard fills
* the verticle space available.
*/
public class CheckerBoard extends GraphicsProgram
{
/* Number of rows */
private static final int NROWS = 8;
/* Number of columns */
private static final int NCOLUMNS = 8;
// Window Size
private static final int height = 1024;
private static final int width = 1024;
/* Runs the program */
public void run()
{
setSize(height,width);
int sqSize = getHeight() / NROWS;
for (int i = 0; i < NROWS; i++)
{
for (int j = 0; j < NCOLUMNS; j++)
{
int x = j * sqSize;
int y = i * sqSize;
GRect sq = new GRect (x, y, sqSize, sqSize);
sq.setFilled(((i + j) % 2) != 0);
add (sq);
}
}
}
}