Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. import java.util.Calendar;
  2. public class RelojFrame extends javax.swing.JFrame {
  3. java.util.Calendar calendario;
  4. int dia, mes, año, hora, minutos, segundos;
  5. private javax.swing.JLabel label;
  6. public RelojFrame() {
  7. inicio();
  8. reloj();
  9. }
  10. private void inicio() {
  11. label = new javax.swing.JLabel();
  12. getContentPane().add(label);
  13. label.setHorizontalAlignment(0);
  14. setBounds(0, 0, 200, 100);
  15. setLocationRelativeTo(null);
  16. setDefaultCloseOperation(3);
  17. }
  18. private void reloj() {
  19. calendario = new java.util.GregorianCalendar();
  20. segundos = calendario.get(Calendar.SECOND);
  21. javax.swing.Timer timer = new javax.swing.Timer(1000, new java.awt.event.ActionListener() {
  22. @ Override
  23. public void actionPerformed(java.awt.event.ActionEvent ae) {
  24. java.util.Date actual = new java.util.Date();
  25. calendario.setTime(actual);
  26. dia = calendario.get(Calendar.DAY_OF_MONTH);
  27. mes = (calendario.get(Calendar.MONTH) + 1);
  28. año = calendario.get(Calendar.YEAR);
  29. hora = calendario.get(Calendar.HOUR_OF_DAY);
  30. minutos = calendario.get(Calendar.MINUTE);
  31. segundos = calendario.get(Calendar.SECOND);
  32. String hour = String.format("%02d : %02d : %02d", hora, minutos, segundos);
  33. String date = String.format("%02d / %02d / %02d", dia, mes, año);
  34. label.setText("<html><center>" + hour + "<br>" + date);
  35. }
  36. });
  37. timer.start();
  38. }
  39. public static void main(String[] args) {
  40. new RelojFrame().setVisible(true);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement