【发布时间】:2014-05-03 09:37:34
【问题描述】:
这是通过 Bresenham 算法在计算出的位置上绘制点的代码:
public void drawBresenhamPoints(Graphics2D g2, List<Point> bresenham) throws InterruptedException
{
Graphics2D g = (Graphics2D) g2;
if(bresenham == null)
return;
g.setColor(Color.DARK_GRAY);
for(int i = 0; i < bresenham.size(); i = i+20)
{
int x = bresenham.get(i).x - pointWidth1/2;
int y = bresenham.get(i).y - pointWidth1/2;
int ovalW = pointWidth1;
int ovalH = pointWidth1;
g.fillOval(x, y, ovalW, ovalH);
// delay
try
{
Thread.sleep(10);
}
catch(Throwable e)
{
System.out.println(e.getMessage());
}
}
}
列表“bresenham”包含所有在 Bresenham 的线条绘制算法的帮助下预先计算的点。我想在“for”循环内设置 1 秒的延迟,以便在 1 秒的间隔后绘制每个点。 “延迟”部分中列出的部分不起作用。如何让“延迟”发挥作用? 更具体地说,我希望以 1 秒的时间间隔在屏幕上看到所有点被一个一个地绘制出来。
【问题讨论】:
-
阅读定时器,不要使用睡眠来避免 EDT 锁定
标签: java swing animation paintcomponent thread-sleep