My GUI is frozen

后端 未结 6 1740
青春惊慌失措
青春惊慌失措 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:14

    The problem is that you're doing the intensive, time-consuming work on the same thread responsible for updating the GUI. SwingWorker allows you to move time-consuming tasks to a separate thread of execution, thereby leaving the UI thread to do its thing uninhibited.

    However, it does add a further complication: affinity. Calling methods on UI components generally requires that you do so from the UI thread. Therefore, you need to use special functionality to get back to the UI thread from the worker thread. SwingWorker also gives you this ability.

    I suggest you read through this documentation.

提交回复
热议问题