package in.swapnilbhoite.projects.subtitlestudio;

/**
 *
 * @author Swapnil Bhoite
 */
public class StopWatch extends Thread {

    private long startTime = 0;
    private long stopTime = 0;
    private boolean running = false;
    public static int instance = 0;

    public void sstart() {
        this.startTime = System.currentTimeMillis() - correction;
        this.running = true;
    }

    public void sstop() {
        this.stopTime = System.currentTimeMillis();
        this.running = false;
    }

    //elaspsed time in milliseconds
    public long getElapsedTime() {
        long elapsed;
        if (running) {
            elapsed = (System.currentTimeMillis() - startTime);
        } else {
            elapsed = (stopTime - startTime);
        }
        return elapsed;
    }

    //elaspsed time in seconds
    public long getElapsedTimeSecs() {
        long elapsed;
        if (running) {
            elapsed = ((System.currentTimeMillis() - startTime) / 1000);
        } else {
            elapsed = ((stopTime - startTime) / 1000);
        }
        return elapsed;
    }

    public void displayTime() {
        this.start();
    }

    public void pauseSW() {
        correction = this.getElapsedTime();
        this.sstop();
    }

    public void resumeSW() {
        this.sstart();
    }

    @Override
    public void run() {
        this.sstart();

        if (instance == 0) {
            time1 = new MyTime();
            time2 = new MyTime();
            while (getElapsedTime() <= Creator.fileLength) {
                time1 = time1.toTime(getElapsedTime());
                Creator.jProgressBarPlayback.setValue((int) ((100 * getElapsedTime()) / Creator.fileLength));
                Creator.jLabelDuration.setText("" + time1 + " / " + time2.toTime(Creator.mediaPlayer.getLength()));
            }
        } else if (instance == 1) {
            //while(true)
            //Edit.jLabel5.setText(""+new MyTime().toTime(getElapsedTime()));
        }
    }
    MyTime time1, time2;
    long correction = 0;
}

@@ -1525,24 +1525,72 @@
 leLength) %7B%0A
+                if (getElapsedTime() %3E 0) %7B%0A    
             
@@ -1629,24 +1629,28 @@
 sedTime());%0A
+    
             
@@ -1743,24 +1743,28 @@
 leLength));%0A
+    
             
@@ -1863,24 +1863,42 @@
 Length()));%0A
+                %7D%0A
             

Fix divide-by-zero exception