Jump to content

Timer help


kingbutton

Recommended Posts

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.

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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