Tema: Cronometro
Ver Mensaje Individual
  #5 (permalink)  
Antiguo 15/08/2013, 08:14
jhonne25_64
 
Fecha de Ingreso: mayo-2013
Ubicación: Armenia, Quindio, Colombia,
Mensajes: 95
Antigüedad: 11 años
Puntos: 3
Respuesta: Cronometro

Ups, disculpa, solo crei que funcionaría.
Este si funciona, espero te sirva:
public class Ventana extends JFrame implements ActionListener{
JButton boton;
JLabel texto;
public Ventana(){
boton= new JButton("Iniciar");
boton.setBounds(10, 10, 80, 20);
boton.addActionListener(this);
getContentPane().add(boton);
texto = new JLabel("0");
texto.setBounds(10, 30, 100, 20);
getContentPane().add(texto);
setLayout(null);
setSize(300, 300);
setLocationRelativeTo(null);
}
public static void main(String a[]){
new Ventana().setVisible(true);
}
public void actionPerformed(ActionEvent e) {
int tiempo;
for ( tiempo = 10; tiempo>=0; tiempo--) {
try {
Thread.sleep (1000);
texto.setText(""+tiempo);
update(getGraphics());
System.out.println(""+tiempo);
} catch (InterruptedException err) {
err.printStackTrace();
}
}
}
}