How to make animation using JLabel in Java/Swing?

前端 未结 1 836
北海茫月
北海茫月 2021-01-29 14:13

I have a final project of a Java course, it is Frog jump game. Here is the video to describe it :

https://www.youtube.com/watch?v=NxWWP9cK24o

I don\'t know how

相关标签:
1条回答
  • 2021-01-29 14:35

    , i only know Thread.sleep

    Well that won't work because the code is executing on the Event Dispatch Thread (EDT) which is the Thread that repaints the GUI. So if you keep telling it to sleep in never gets a chance to repaint itself.

    So if you want to use Thread.sleep, you need to start a separate Thread.

    Read the section from the Swing tutorial on Concurrency for more information. Maybe you could also use a SwingWorker as discussed in the tutorial for the worker Thread.

    0 讨论(0)
提交回复
热议问题