Javaを使用してチェッカーボードを描画しようとしています。私はJavaが初めてです。だから、どんなアドバイスも役に立ちます。
更新: メイン メソッドに追加しました。Mac ターミナルで正常にコンパイルできました。ただし、java Checkerboard
実行すると、下部にアイコンが表示され、その後消えてグラフィックが表示されませんでした。ここで何が問題なのですか?コードは次のとおりです。
import acm.graphics.*;
import acm.program.*;
/*
* This class draws a checkerboard on the graphics window.
* The size of the chcekerboard is specified by the constants NROWS
* and NCOLUMNS, and the checkerboard fills the vertical space available.
*/
public class Checkerboard extends GraphicsProgram {
public static void main(String[] args){
Checkerboard c = new Checkerboard();
c.run();
}
// Number of rows
private static final int NROWS = 8;
//Number of columns
private static final int NCOLUMNS = 8;
//Runs the program
public void run() {
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);
}
}
}
}