Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Adding a countdown timer?

+7 votes
What is the best way to add a countdown timer to the PokeChase project? I thought it should be a time variable that updates within the drawMovingRandom method that will then update in the drawingPanel.  However, it would be in miliseconds which would make it update too often and then crash.  Ideas?
asked Oct 12, 2017 in CSC 211 (F17) by Nicholas Garling (100 points)

2 Answers

+2 votes
You are correct in thinking a time variable that updates throughout a loop should be used to create the countdown timer. Because you will be sleeping your loop in milliseconds your time variable will also be in milliseconds. You will need to find out the relationship between your current time units and your desired time units and perform an operation.
answered Oct 12, 2017 by Matthew Kuechenberg (100 points)
+1 vote
It is important that when using the relationship between seconds and miliseconds, that the divison takes into account integer or double division.  Keep that in mind in how specific you want your time to be and how often you want it to be refreshed.  Matt's answer did work.  It does have to be displayed in the drawing panel, and not the console.  So no printLns
answered Oct 12, 2017 by Nicholas Garling (100 points)