小编mat*_*tan的帖子

等到线程完成

我有一个函数,它的内部线程可以做某事

public static void animate(int column,Image image)
{

    new Thread(new Runnable() {
        public void run() {
            try {

                    /* Code */
                    repaint();
                    Thread.sleep(500);
                    repaint();

            } catch (InterruptedException ex) {
            }
        }
    }).start();
}
Run Code Online (Sandbox Code Playgroud)

我在 updateBoard 函数中调用的动画函数,然后是 i++。我想让函数动画在线程结束之前不继续 I++

在函数内部,animate我使用repaint()了 Swing 中的函数,当我尝试使用.join()它的块repaint()线程时。

public static void updateBoard(int column, Image image) {
    int i = 0;
    animate(column,image);
    i++;
}
Run Code Online (Sandbox Code Playgroud)

java swing multithreading

1
推荐指数
1
解决办法
111
查看次数

标签 统计

java ×1

multithreading ×1

swing ×1