java stopwatch standalone

Posted on 2007-04-06
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.
Question by:mack04
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 24

Expert Comment

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;

LVL 17

Accepted Solution

contactkarthi earned 250 total points
ID: 19505424

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jsp login check 12 67
ejb mdb examples 1 39
Fast way to search item into Java Array (Rhino compatible) 2 47
Coding for the first time 9 103
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses

752 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