Boa tarde.
Eu estou com dificuldade em fazer um programinha. Seria como um cronometro, a pessoa coloca quanto tempo quer praticar algo e quanto tempo que descansar. Consegui converter a hora do sistema, mas o programa esta entrando em loop infinito.
Alguém pode me ajudar?
Obrigado
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.SimpleFormatter;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
public Tela() {
initComponents();
}
public void converteHora() {
boolean aux = false;
while (aux == false) {
long miliSegundos = System.currentTimeMillis() - 10800000;
long totalSegundos = miliSegundos / 1000;
long segundoAtual = totalSegundos % 60;
long totalMinutos = totalSegundos / 60;
long minutoAtual = totalMinutos % 60;
long totalHora = totalMinutos / 60;
long horaAtual = totalHora % 24;
String hora = Long.toString(horaAtual);
String min = Long.toString(minutoAtual);
String sec = Long.toString(segundoAtual);
lblContador.setText(hora + " : " + min + " : " + sec);
System.out.println(aux);
if (totalMinutos == 16) {
aux = true;
}
}
}
private void btnComecarActionPerformed(java.awt.event.ActionEvent evt) {
// clicar no lblComecar mostra o tempo correndo
converteHora();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Tela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Tela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Tela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Tela.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Tela().setVisible(true);
}
});
}
private javax.swing.JButton btnComecar;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField jTextField1;
private javax.swing.JLabel lblContador;
private javax.swing.JTextField tempoDescansar;
private javax.swing.JTextField tempoEstudar;
}