Domanda

Ho provato a resettare il timer in base al tempo corrente dopo clic su un pulsante, ma pretende molto lavoro. Aiuto: - (

private long startTime  = System.currentTimeMillis();
Timer timer  = new Timer(1000, this);
timer.start();

timer.stop();
long endTime    = System.currentTimeMillis();
long timeInMilliseconds = (endTime - startTime);

timer.reset();
È stato utile?

Soluzione 2

La soluzione per il mio programma. Grazie a tutti.

   public class mainClass {
        private long startTime  = System.currentTimeMillis();
        Timer timer  = new Timer(1000, this);
        .....
    }

    public mainClass {
        timer.start();
    }

    //Everytime the button stop clicked, the time will stop and reset to the most current time of the system
    public actionPerformed () {
        timer.stop();
        long endTime    = System.currentTimeMillis();
        long timeInMilliseconds = (endTime - startTime);

        **startTime  = System.currentTimeMillis();** ACCEPTED
    }

Altri suggerimenti

La mia sfera di cristallo magico dice che si sta utilizzando un javax.swing.Timer e che non esiste un metodo reset (), si parla di riavvio ().

Ma allora potrebbe essere sbagliato, sarebbe bello se tu fossi un po 'più esplicito su ciò che si sta facendo ...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top