I have the following code in a JPanel class which is added to a another class (JFrame). What I\'m trying to implement is some sort of a stopwatch program.
st
long startTime = System.currentTimeMillis();
Timer timer = new Timer(100,new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
long elapsedTime = System.currentTimeMillis()-startTime;
long mil = elapsedTime%1000;
long sec = elapsedTime/1000%60;
long min = elapsedTime/60000%60;
long hr = elapsedTime/3600000;
label.setText(String.format("%02d:%02d:%02d.%03d", hr,min,sec,mil));
}
});
timer.start();