How to handle Timers correctly in Java?

前端 未结 5 413
情书的邮戳
情书的邮戳 2021-01-21 01:13

I want my timer to execute the actionPerformed method only one time once it 5 seconds the time but it is writing in the console \"Hello\" lots of times:

import j         


        
5条回答
  •  猫巷女王i
    2021-01-21 01:40

    As already mentioned, it's better to use java.util.Timer, but you can also use setRepeats() before starting:

    timer.setRepeats(false);
    

提交回复
热议问题