Ejemplo Timer
/**
*
*
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Ventanaven=new Ventana();
ven.setVisible(true);
// TODO code application logic here
}
}
package ejemplotimer;
import java.awt.Color;
import java.util.TimerTask;
importjava.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
/**
*
* @author sergio
*/
public class Juego extends TimerTask {
JButton botones[]=new JButton[4];Color colores[]=new Color[4];
public Juego()
{
botones[0]=Ventana.color1;
botones[1]=Ventana.color2;
botones[2]=Ventana.color3;botones[3]=Ventana.color4;
colores[0]=Color.BLUE;
colores[1]=Color.RED;
colores[2]=Color.GREEN;
colores[3]=Color.YELLOW;
}
@Override
public voidrun() {
botones[0].setBackground(null);
botones[1].setBackground(null);
botones[2].setBackground(null);
botones[3].setBackground(null);
int seleccionado =(int) Math.round((Math.random()*3));
botones[seleccionado].setBackground(colores[seleccionado]);
}
}
package ejemplotimer;
import java.util.Timer;
/***
* @author sergio
*/
public class EjemploTimer {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
long delay=1000;long delay2=2000;
Timer color1=new Timer();
Timer color2=new Timer();
color1.schedule(new Alumbrar("Rojo"), 0,delay );
color2.schedule(newAlumbrar("Verde"), 0,delay2);
// TODO code application logic here
}
}
package ejemplotimer;
import java.util.Timer;
/**
*
* @author personal2
*/
public class Ventana extends...
Regístrate para leer el documento completo.