Java Swing: Change Text after delay

后端 未结 3 1459
一向
一向 2020-12-06 23:08

Basically, I have this game where once guesses the correct answer it starts a new game with a new word. I want to display Correct! but after three seconds, chan

3条回答
  •  太阳男子
    2020-12-06 23:23

    if these piece of code is in the event handlers, then you are holding up the UI thread, and it is not going to work as UI update will only happens after you finished your work in the event handlers.

    You should create another thread do the work of "sleep 3 second, and change the text field, and trigger repaint". Using Timer or similar utilities is the easiest way to achieve what I am describing.

提交回复
热议问题