Pregunta

He tratado de restablecer el temporizador basado en la hora actual después de hacer clic en un botón, pero no funciona. Ayuda: - (

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();
¿Fue útil?

Solución 2

La solución para mi programa. Gracias a todos.

   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
    }

Otros consejos

Mi bola de cristal dice que está utilizando un javax.swing.Timer y que no existe un método reset (), se llama reinicio ().

Pero entonces podría estar equivocado, sería bueno si fuera un poco más explícito acerca de lo que está haciendo ...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top