Solved

java stopwatch standalone

Posted on 2007-04-06
4
777 Views
Last Modified: 2013-11-23
I need a standalone java stopwatch program with the tester. it must have 3 buttons, start, stop and exit. it must keep elapsed time after the stop and start will contiue the counting. is not for web applications. need as soon as possible.
0
Comment
Question by:mack04
4 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 18868706
Hi, I do such things from the program itself, but here is a building block without gui:

public class Stopwatch
{
   /**
    * Records the start time for <B>Sy.startWatch()</B>, <B>Sy.lapWatch()</B> & <B>Sy.stopwatch()</B>.
    */
   private static long clockStart = 0;

   /**
    * Records the lap time for <B>Sy.startWatch()</B>, <B>Sy.lapWatch()</B> & <B>Sy.stopwatch()</B>.
    */
   private static long clockLap = 0;


   /**
    * Starts the clock for elapsed time measurements.
    * <P>
    * Records the current time. For a closed interval call <B>Sy.stopWatch()</B>,<BR>
    * for repeated intervals call <B>Sy.lapWatch()</B>.
    * </P>
    */
   public static void startWatch()
   {
      clockStart = clockLap = System.currentTimeMillis();
   }


   /**
    * Measures the elapsed time since the last <B>Sy.startWatch()</B>.
    * <P>
    * Also the time is set for the next <B>Sy.lapWatch()</B> call.
    * </P>
    *
    * @return    The # of milliSeconds.
    */
   public static long stopWatch()
   {
      return((clockLap = System.currentTimeMillis()) - clockStart);
   }


   /**
    * Measures the elapsed time between successive calls.
    * <P>
    * For this method the clock seems to be reset at any previous call to<BR>
    * <B>Sy.startWatch()</B>, <B>Sy.lapWatch()</B> or <B>Sy.stopWatch()</B>.
    * </P>
    *
    * @return    The # of milliseconds.
    */
   public static long lapWatch()
   {
   long now = System.currentTimeMillis();
   long lap = now - clockLap;

      clockLap = now;
      return(lap);
   }
}

;JOOP!
0
 
LVL 17

Accepted Solution

by:
contactkarthi earned 250 total points
ID: 19505424
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 38
Java Timer (static) 9 43
hibernate insert example 13 29
Is there a simpler dropbox system? 10 21
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question