Ver Mensaje Individual
  #8 (permalink)  
Antiguo 01/09/2011, 16:45
Avatar de KenUston
KenUston
 
Fecha de Ingreso: agosto-2011
Mensajes: 6
Antigüedad: 12 años, 8 meses
Puntos: 0
De acuerdo Respuesta: Actualizar JLabel con Timer

Para el que le pueda servir, lo hice de la siguiente forma:

Un gestor (GestorTime) con el siguiente codigo:

public class GestorTime {

static Date FechaSystem = new Date();
static SimpleDateFormat fechaformato = new SimpleDateFormat("EEEEEEEEE dd/MM/yyyy HH:mm:ss");
public static String FfechaSystem = fechaformato.format(FechaSystem);

public static void setFfechaSystem(String ffechaSystem) {
FfechaSystem = ffechaSystem
}

public static String getFfechaSystem() {
return FfechaSystem;
}
}

Por otro lado, donde tengo la JToolBar y la lbl puse esto:

Timer timer = new Timer (1000, new ActionListener ()
{

public void actionPerformed(ActionEvent e)
{
Date HorNew = new Date();
SimpleDateFormat fechaforma = new SimpleDateFormat("EEEEEEEEE dd/MM/yyyy HH:mm:ss");
String FfechaSystemA = fechaforma.format(HorNew);


GestorTime.setFfechaSystem(FfechaSystemA);
LblEboHora.setText(GestorTime.getFfechaSystem());

}

});
timer.start();

Lo que hace esto es sencillo, cada 1 segundo:
1 - Crea una nueva instancia de Date con todo ese formato
2 - Se la setea a la variable del GestorTime
3 - Se refresca el setText de la lbl, mediante el metodo get del GestorTime.

Simple y sencillo, pero le di dos millones de vueltas, ya tendré mas experiencia jeje.

Chauuu.