Skip to content
Advertisement

How to pause and resum a timer in Java

I have a small game where I need to pause the timer when the user press Pause button and after to resume the timer and to continue to increase the seconds when the user press the Resume button. I researched a lot and I tried different solutions but none worked for me. Can you please help me to achieve this functionality ? Here is my code:

JavaScript

Thanks for reading this.

Advertisement

Answer

Try using a Swing timer.

JavaScript

Then you can use stop() and start() methods to pause and resume action. Check the javaDocs for more details.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement