Java: while loop freezes program

前端 未结 3 965
鱼传尺愫
鱼传尺愫 2021-01-29 06:50

I\'m making a game and i need to update the JProgressBar every 3 seconds. To do that i use a while loop. The problem is that my program freezes becuse of the while loop (i read

3条回答
  •  囚心锁ツ
    2021-01-29 06:54

    You will need to use threads for that. But be careful, and don't try to update the GUI component (JProgressBar) from a thread that does not own the progress bar.

    You should use SwingUtilities.invokeLater to do that.

提交回复
热议问题