Source Code : Used for timing events with millisecond precision.
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Used for timing events with millisecond precision.
/*********************************************************************
* Used for timing events with millisecond precision.
*
* @version 2001-07-03
* @since 2001-07-03
* @author <a href="http://croftsoft.com/">David Wallace Croft</a>
*********************************************************************/
public final class Stopwatch
// ////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////
{
private long elapsedTime;
private boolean isTicking;
private long startTime;
// ////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////
/*********************************************************************
* Returns the elapsed time in milliseconds.
*********************************************************************/
public synchronized long getElapsedTime()
// ////////////////////////////////////////////////////////////////////
{
if (isTicking) {
return System.currentTimeMillis() - startTime;
} else {
return elapsedTime;
}
}
// ////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////
public synchronized void reset()
// ////////////////////////////////////////////////////////////////////
{
elapsedTime = 0;
isTicking = false;
}
public synchronized void start()
// ////////////////////////////////////////////////////////////////////
{
if (isTicking) {
throw new IllegalStateException("already started");
}
isTicking = true;
startTime = System.currentTimeMillis();
}
public synchronized void stop()
// ////////////////////////////////////////////////////////////////////
{
if (!isTicking) {
throw new IllegalStateException("not started");
}
elapsedTime = System.currentTimeMillis() - startTime;
isTicking = false;
}
// ////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////
}
Thank with us