创建外形上,我需要放置在画布位置整形JavaFX中画布
Class Square
绘制一个正方形,并插入到canvas
位置
public class Square{
//calculate the position of the rand column to
//draw and insert in the position of the canvas
public void drawSquare(int posX, int posY, GraphicsContext gc) {
//Square Shadow
//gc.rect(posX, posY, w, h);
gc.rect(posX + 1, posY + 53, 50, 50);
gc.fill();
gc.beginPath();
//Square
gc.beginPath();
gc.setFill(Color.WHITE);
gc.setStroke(Color.BLACK);
gc.setLineWidth(2);
//gc.rect(posX, posY, w, h);
gc.rect(posX + 1, posY + 53, 48, 48);
gc.fill();
gc.stroke();
}
}
新Canvas instance
与height = 450
和width = 600
Canvas canvas = new Canvas();
canvas.setHeight(450);
canvas.setWidth(600);
and GraphicsContext
to draw square
GraphicsContext gc = canvas.getGraphicsContext2D();
这个循环中,canvas
, 画4 rows
和6 columns
与square
和我的怀疑是怎么line
来calculate the position
和column
到draw square
,并在画布position
插入当我打电话pieces.drawSquare(i, j, gc);
和方法drawSquare
创建形状,但无疑是如何position
他们如果是多于一个的形状
for (int i = 0; i < 4; i++) { //4 rows
for (int j = 0; j < 6; i++) { //6 columns
Piece pieces = new Piece();
pieces.drawSquare(i, j, gc);
}
这个图像是例如,
和物镜是填补4行和6列
我已经想到了将画布的大小和宽度与形状的大小和宽度,但它不工作,也许可以有另一种解决方案
我无法读到的一切,但我的理解是,你要填充矩形画布,除了第一行? –