import java.applet.*; import java.awt.*; public class hilos4 extends Applet { Thread.currentThread().setPriority(Thread.MAX_PRIORITY); NuevoHilo h1 = new NuevoHilo(50,"J"); // SE MANDA LA POSICION "Y" Y LA LETRA COMO PARAMETROS. NuevoHilo h2 = new NuevoHilo(100,"A"); NuevoHilo h3 = new NuevoHilo(150,"V"); NuevoHilo h4 = new NuevoHilo(200,"A"); h1.start(); h2.start(); h3.start(); h4.start(); try { Thread.sleep(10000); } catch (Exception e) {} h1.stop(); h2.stop(); h3.stop(); h4.stop(); public void update(Graphics g) // Muestra el frame actual { paint(g); } // llamar a paint public void paint(Graphics g) { Thread HiloActual = Thread.currentThread(); g.drawString(HiloActual.Letra, HiloActual.x, HiloActual.y); } } class NuevoHilo implements Runnable { int x = 40; // POSICION ORIZONTAL. int y; // POSICION VERTICAL. String Letra; // LETRA QUE SE IMPRIME. int N = 0; // CANTIDAD DE LETRAS. private boolean ciclo = true; // CONTROL DEL CICLO private Thread hilo; public NuevoHilo (int Y, String Letra) { hilo = new Thread(this); y = Y; this.Letra = Letra; } public void run() { while ( ciclo ) { if (N < 10) { x += 10; N += 1; } else ciclo = false; repaint(); try { hilo.sleep(500); } catch (InterruptedException e) {} } } public void start() { hilo.start(); } { hilo.stop(); } }