martes, 24 de enero de 2012

Programa con hilos(Solo acepta números enteros)

Clase uno: Genera Enteros


public class GeneraEnteros extends Thread {
int n;
public GeneraEnteros(int valorN)
 {
n = valorN; }

public void run() {
for (int i = 0; i < n; i++) {
System.out.println("Numero "+i);
try {
sleep(1000);
} catch (InterruptedException e) {
System.out.println("Interrupcion hilo ");}
}
System.out.println("Termina hilo " );
}
}

clase dos UsaGeneraEnteros

import javax.swing.JOptionPane;
public class UsaGeneraEnteros{
public static void main (String[] args) {
int numero = Integer.parseInt(JOptionPane.showInputDialog("Cuantos terminos?"));
GeneraEnteros serie =new GeneraEnteros(numero);
serie.start();
}
}

No hay comentarios:

Publicar un comentario