Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/jcmouse/public_html/app/code/include/model/database/db.class.php on line 18

Deprecated: Function eregi_replace() is deprecated in /home/jcmouse/public_html/app/code/include/model/database/pregunta.php on line 161

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/jcmouse/public_html/app/code/include/model/database/db.class.php on line 18
Ajuda: Cronômetro regressivo HH:mm:ss - Code Army!
Te encuentras en el foro de Java

Ajuda: Cronômetro regressivo HH:mm:ss


Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/jcmouse/public_html/app/code/include/model/database/db.class.php on line 18
problem
08/02/2020 10:24
fabioargenton
Rango: Soldado
08/02/2020 10:19
Brasil
1
2
Fecha de ingreso
Ubicacion
Preguntas
Respuestas

Pessoal, possuo um método que simula um cronômetro progressivo e mostra na tela HH:mm:ss começando em 00:00:00, gostaria de colocar uma opção para que este cronômetro seja regressivo, ou seja, eu defino um tempo (Ex.: 01:02:30) e ao clicar em INICIAR ele comece a rodar HH:mm:ss a partir deste tempo até chegar no 00:00:00, por favor, podem me ajudar:

Meu código atual (Cronômetro normal):

  1. //Variáveis
  2. private Timer timer;
  3. private int currentSegundo = 0;
  4. private int currentMinuto = 0;
  5. private int currentHora = 0;
  6. private int velocidade = 1000;
  7.  
  8. //Construtor da tela que inicia o método
  9. public viewEMB_MesaBip() {
  10. initComponents();
  11. iniciarCronometro(lblCronometro);//Aqui está o método do cronômetro
  12. }
  13.  
  14. //Botão INICIAR
  15. private void btnIniciarActionPerformed(java.awt.event.ActionEvent evt) {
  16. timer.restart();//Inicia a Thread do método para que o cronômetro rode
  17. }
  18.  
  19. //Metodo CRONOMETRO (AQUI PRECISO DE AJUDA PARA SER REGRESSIVO)
  20. private void iniciarCronometro(JLabel label) {
  21. ActionListener action = new ActionListener() {
  22. public void actionPerformed(ActionEvent e) {
  23. currentSegundo++;
  24. if (currentSegundo == 60) {
  25. currentMinuto++;
  26. currentSegundo = 0;
  27. }
  28. if (currentMinuto == 60) {
  29. currentHora++;
  30. currentMinuto = 0;
  31. }
  32. String hr = currentHora <= 9 ? "0" + currentHora : currentHora + "";
  33. String min = currentMinuto <= 9 ? "0" + currentMinuto : currentMinuto + "";
  34. String seg = currentSegundo <= 9 ? "0" + currentSegundo : currentSegundo + "";
  35. label.setText(hr + ":" + min + ":" + seg);
  36. }
  37. };
  38. this.timer = new Timer(velocidade, action);
  39. this.timer.start();
  40. }
  41.  
  42. //Metodo para parar o cronometro
  43. private void zerarCronometro(JLabel label) {
  44. timer.stop();
  45. currentHora = 0;
  46. currentMinuto = 0;
  47. currentSegundo = 0;
  48. label.setText("00:00:00");
  49. }

problem
 
.
X

Se parte de Code Army!

Esta acción es solo para usuarios registrados