Programacion Concurrente
  Poetas
 

import java.applet.Applet;
import java.awt.*;

public class Poetas extends Applet{

 public void init() {
 TextArea mostrar= new TextArea(" ", 10,30, TextArea.SCROLLEARS VERTICAL_ONLY);
 add(mostrar);
 Infantil infantil=new Infantil(mostrar);
 Revolucionario revolucionario = Revolucionario(mostrar);
 infantil.start();
 revolucionario.start();
 }
}

class Infantil extends Thread{
 private TextArea mostrar;

 public Infantil(TextArea mostrar){
  this.mostrar=mostrar;
 }

 public void run(){
  while(true){
   mostrar.append("Mary tenia un corderito\n");
   mostrar.append("Su piel era blanca como la nieve\n\n");
   try{
    Thread.sleep(5000);   }
   catch (InterruptedException e){
    mostrar.append ("excepcion de inactividad falla de diseño\n");
   }
  }
 }
}

class Revolucionario extends Thread{
 private TextArea mostrar;

 public Revolucionario(TextArea mostrar){
  this.mostrar=mostrar;
 }

 public void run(){
  while(true){
   mostrar.append("Alaben a Marx\n");
   mostrar.append("y  pasen las municiones\n\n");
   try{
    Thread.sleep(5000);
   }
   catch (InterruptedException e){
    mostrar.append ("excepcion de inactividad falla de diseño\n");
   }
  }
 }
}

 
   
 
Este sitio web fue creado de forma gratuita con PaginaWebGratis.es. ¿Quieres también tu sitio web propio?
Registrarse gratis