Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javafx绘制带有嵌套循环的49个矩形?_Java_Arrays_Javafx_Nested Loops_Rectangles - Fatal编程技术网

如何使用javafx绘制带有嵌套循环的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

我必须使用一个双数组来制作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; 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);