我想用Java繪製棋盤。 我是Java新手。所以任何建議都會有幫助。Java:Mac終端無法顯示Java圖形
更新:我在主要方法中添加。我在Mac終端中成功編譯了它。但是,當我做了java Checkerboard
時,ICON出現在底部,然後消失,沒有圖形出現。這裏有什麼問題?其代碼如下:
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);
}
}
}
}
相關:http://stackoverflow.com/q/3442971/335858 – dasblinkenlight
我沒有使用Ecilpse。我正在使用mac的終端 – mynameisJEFF