Hilo2.java
Código PHP:
package catedra;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextField;
public class Hilo2 extends Thread{
static Thread hilo2;
static JTextField num;
Random rnd = new Random();
public Hilo2(){
hilo2=new Thread();
}
@Override
public void run(){
while (true) {
for (int i = 0; i < 10; i++) {
//num.setText(Integer.toString(i));
num.setText(Integer.toString( (int) (Math.random ()* 100000000) ));
//num.setForeground(Color.red);
try {
hilo2.sleep(500);
} catch (InterruptedException ex) {
Logger.getLogger(Hilo2.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
public static void iniciarHilo(JTextField num){
hilo2=new Hilo2();
hilo2.start();
Hilo2.num=num;
}
public static void detenerHilo(JTextField num){
hilo2.stop();
}
public static void pausarHilo2(JTextField num){
try {
Thread.sleep(10000); //tiempo en milisegundos.
} catch (Exception e) {
e.printStackTrace();
}
}
}
Agradezco de antemano tu ayuda.
Saludos