My GUI is frozen

后端 未结 6 1748
青春惊慌失措
青春惊慌失措 2020-12-11 13:45

I have something I can\'t understand: my Swing GUI contains a \'play\' and \'pause\' button. I have also a static variable that defines \'ON\' and \'OFF\' states. (The main

6条回答
  •  清歌不尽
    2020-12-11 14:11

    You need to read Concurrency in Swing to understand how the EDT and SwingWorkers operate.

    All GUI updates are executed on the EDT so when you click a GUI component any method that this calls will be executed on the EDT. If this is a time consuming process then this will block the EDT from executing any futher GUI updates. Hence your GUI is freezing and you can't click the pause button.

    You need to use SwingWorker to execute the time consuming process on another thread. The link I provided above details how to do this.

提交回复
热议问题