我正在使用一個簡單的棋盤程序,它工作正常,但它非常小。我嘗試使用acm.graphics.setsize方法調整窗口大小,但直到放置圖形對象後才調整大小。我是否需要做一些事情來「沖洗」對程序的更改,使其正常工作?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);
}
}
}
}
我注意到由於某種原因,有人提出這個問題-1。大家都知道,我一直在網上搜索,特別是在acm文檔中尋找這個看似基本問題的答案。 – cassius