Hilo1.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 Hilo1 extends Thread{
static Thread hilo1;
static JTextField num;
Random rnd = new Random();
public Hilo1(){
hilo1=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) ));
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
Logger.getLogger(Hilo1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
public static void iniciarHilo(JTextField num){
hilo1=new Hilo1();
hilo1.start();
Hilo1.num=num;
}
public static void detenerHilo(JTextField num){
hilo1.stop();
}
public static void pausarHilo(JTextField num) throws InterruptedException{
try {
Thread.sleep(10000); //tiempo en milisegundos.
} catch (Exception e) {
e.printStackTrace();
}
}
}