0

How can you implement some kind of timer, to know how much time did user spend for one round of a game?

Tomi S
  • 197
  • 1
  • 6
  • 17

2 Answers2

0

One can easily find the time spent by a user on one round of a game by using System.nanoTime() function. However if you want to implement in a game, you would probably like the timer to also be displayed to the user, you can you use multi-threading for the same.

stack programmer
  • 3,206
  • 1
  • 18
  • 12
  • Nanoseconds are not only unnecessarily granular, but they are typically inaccurate. Especially when you consider the numerous levels of abstraction between the program being written and the actual clock. – Peaches491 Jun 18 '11 at 20:08
0

Getting System.currentTimeMillis will get your system time to the millisecond. If you want to do a Swing event intermittently, such as displaying the current time in a stop watch or a simple animation, then a Swing Timer would work well.

Hovercraft Full Of Eels
  • 276,051
  • 23
  • 238
  • 346