Jump to content

Timer help


Recommended Posts

Posted

My timer is resetting after 5 seconds, and I'm not sure why.

private long startTime;

	public void onStart() {

		startTime = System.currentTimeMillis();

	}
public final String formatTime(final long ms) {

		long s = ms / 1000, m = s / 60, h = m / 60;
		s %= 6;
		m %= 60;
		h %= 24;
		return String.format("%02d:%02d:%02d", h, m, s);

	}
public void onPaint(Graphics2D g) {

		long runTime = System.currentTimeMillis() - startTime;
		g.drawString("Run Time :" + formatTime(runTime), 10, 290);
	}

I put all the important bits down.

 

Posted
1 minute ago, kingbutton said:

Wasn't a coppyyy pastaa :(

I typed it out to try and understand the lines and reasonings, makes it easier for me to remember how to do things.

xD, why you roasting

If you want to understand it, read what he did and do your own version of a timer. 

This one is somewhat unique to avg timer classes. 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...