Jump to content

Adding a couter


Recommended Posts

Posted

Declare these as globals (secs,mins,hrs can be declared inside onPaint() if you'd like)

long startTime;
long timeRunning;
long seconds, minutes, hours;

and set

onStart(){
   startTime = System.currentTimeMillis();
}

and

onPaint(Graphics2D g){
   timeRunning = System.currentTimeMillis() - startTime;
  
   hours = timeRunning / 3600000;
   timeRunning -= hours * 3600000;
   minutes = timeRunning / 60000;
   timeRunning -= minutes * 60000;
   seconds = timeRunning / 1000;

   // and now just print it, for example
   g.drawString("Time: " + hours + "h " + minutes + "m " + seconds + "s", x, y);
}

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...