我想知道是否有某种方法可以创建一个临时图形,我可以对其进行多次更改,当我觉得所有更改都已完成时,仅重新绘制一次框架,以对图形进行更改可见的。
一个字符串类比是:
for (int row = 1; row <= N; row++) {
for (int col = 1; col <= N; col++) {
s.append(String.format("%d %d%s", row, col , delim));
}
}
System.out.println("created points : \n" + s.toString());
// @^^ im only printing the string after all work has been done , instead of at the end of each loop
这就是我想要做的:
create a 5x5 grid (so it has 25 square sites)
start loop:
at random , open each site , paintIt(x,y); // x,y are co-ords of the site opened
if(connected(topRow,bottomRow))
break;
else
loop again;
.
.
.
paintIt(int x , int y) :
if(topRow,bottomRow are connected)
// this condition means that system "percolates"
for(some row){
for(some col){
if(site(row,col) is open)
paint the sites LIGHT_BLUE;
repaint the frame to make changes visible;
// @^^ this N*N times repaint is what im trying to avoid
}
}
else if(site at (x,y) connected to topRow)
// this means that the site at (x,y) is "full"
paint the site LIGHT_BLUE;
repaint the frame to make changes visible;
else
paint the site WHITE;
repaint the frame to make changes visible;
我的问题是,paintIt()
方法只获取已打开站点的坐标,当打开一个特定站点时,整个系统“渗透”,我必须绘制所有打开的站点 LIGHT_BLUE,为此,目前我必须运行一个双 for() 循环,它会一一检查 2D 数组的每个站点是否打开,并将画笔设置为相应地保持 LIGHT_BLUE,然后重新绘制整个帧,只是为了更改一个特定的站点颜色.
正在发生的事情的图像:
(4,4)
是使系统渗透的站点。