如何使用javafx绘制带有嵌套循环的49个矩形?
我必须使用一个双数组来制作49个正方形。我只给了我一个矩形如何使用javafx绘制带有嵌套循环的49个矩形?,java,arrays,javafx,nested-loops,rectangles,Java,Arrays,Javafx,Nested Loops,Rectangles,我必须使用一个双数组来制作49个正方形。我只给了我一个矩形 Rectangle[][] rectArray = new Rectangle[7][7]; //grid is a GridPane containing 49 rectangles. GridPane grid = new GridPane(); //---- add 49 rectangles to the grid pane, it is recommended to use nested loops for(int i = 0
Rectangle[][] rectArray = new Rectangle[7][7];
//grid is a GridPane containing 49 rectangles.
GridPane grid = new GridPane();
//---- add 49 rectangles to the grid pane, it is recommended to use nested loops
for(int i = 0; i < rectArray.length; i++)
{
for(int j = 0; j < rectArray.length; j++)
{
rectArray[i][j] = new Rectangle(470/7,390/7);
rectArray[i][j].setStroke(Color.BLACK);
rectArray[i][j].setFill(Color.WHITE);
grid.getChildren().add(rectArray[i][j]);
}
}
Rectangle[]rectary=新矩形[7][7];
//grid是一个包含49个矩形的网格窗格。
GridPane grid=新建GridPane();
//----在网格窗格中添加49个矩形,建议使用嵌套循环
for(int i=0;i
添加
在将矩形添加到网格之前。现在所有的矩形都放在同一个位置(0,0),所以它们重叠,看起来像一个。另一个选项是使用。
GridPane.setConstraints(rectArray[i][j], i, j);