I’m looking to make a simple(for now) stopwatch application in java which I would eventually like to port to android devices, but first I’m just working on a simple computer run version and I’m wondering what I should do as far as displaying the elapsed time on the screen, so for I just have a JPanel with start and stop buttons, What would be the best way to actually display the time? I feel like simply drawing the numbers and erasing them is slow and inefficient, how can I do this so that the GUI is rapidly updated with the correct current time? I know how to compute the elapsed time using System.currentTimeMillis(), I’m just looking for the best way to display the time on screen that can be updated rapidly. I’d like to show it to at least the hundredth of a second which means the screen needs to be changing that often. Any suggestions?
Should I just use a JLabel?
You can separate Hours, Minutes, Seconds, Milliseconds into different `JLabel’s.
So using
TimerorExecutorServiceyou would updateJLabelwith Seconds and Milliseconds very often.Other
JLabels update only when needed, i.e. a minute elapsed.