我想學習這本書的Java圖形程序The Art and Science of Java
練習寫畫一個金字塔
演習書The Art and Science of Java第129頁
我的問題是金字塔應該以窗口爲中心
import acm.program.*;
import acm.graphics.*;
public class pyramid extends GraphicsProgram {
public void run() {
for (int i = 0; i < BRICK_IN_BASE; i++) {
for (int j = 0; j < i; j++) {
int x = BRICK_WIDTH * j ;
int y = BRICK_HEIGHT * i;
GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
add(brick);
}
}
}
private static final int BRICK_WIDTH =30 ;
private static final int BRICK_HEIGHT =20 ;
private static final int BRICK_IN_BASE = 12;
}
高度應該是'BRICK_IN_BASE * BRICK_HEIGHT'雖然 – Voo
@Voo是,該死的複製粘貼;) – Thomas
@thomas感謝的人,,試過,但不會像變得像一個金字塔三角形 – tito11