1 
   2 /**
   3  * HiloAwt.java
   4  * @author: Luis Alejandro Bernal Romero (aztlek)
   5  *
   6  * Un ejemplo de hilos funcionando al mismo tiempo. Pero con interfaz
   7  * gráfica que permite ver realmente el paralelismo.
   8  */
   9 
  10 import java.io.*;
  11 import java.awt.*;
  12 
  13 public class HiloAwt extends Frame implements Runnable{
  14     TextArea areaTextoPadre;
  15     TextArea areaTextoHijo;
  16 
  17     public HiloAwt(){
  18     areaTextoPadre = new TextArea();
  19     areaTextoHijo = new TextArea();
  20     setLayout(new GridLayout(1, 2));
  21     add(areaTextoPadre);
  22     add(areaTextoHijo);
  23     } // HiloAwt
  24 
  25     public void imprPadre(){
  26     for(;;){
  27         areaTextoPadre.setText(areaTextoPadre.getText() + " soy el padre" + "\n");
  28     }
  29     } // imprPadre
  30 
  31     public void run(){
  32     for(;;){
  33         areaTextoHijo.setText(areaTextoHijo.getText() +" soy el hijo" + "\n");
  34     }
  35     }
  36     public static void main(String[] argv){
  37     HiloAwt hilo = new HiloAwt();
  38     Thread h = new Thread(hilo);
  39     hilo.show();
  40     hilo.setTitle("HiloAwt");
  41     h.start();
  42     hilo.imprPadre();
  43     }
  44 
  45 }
  46 

Java/Programas/HiloAwt.java (last edited 2008-04-20 14:38:53 by localhost)