import java.awt.*; import javax.swing.JFrame; import java.awt.event.*; import javax.swing.JPanel; import java.awt.Graphics; // Prototipo de una aplicacon de ventana // 1.- Se crea la clase que extienda a la clase Frame, JFrame o Window public class VentanaAnimacion extends JFrame { AreaDeDibujo Lienzo; public VentanaAnimacion() { Lienzo = new AreaDeDibujo(); this.getContentPane().setLayout(null); // Contenedor nulo this.setTitle("Topicos de la animacion"); // Titulo de la ventana this.setResizable(false); // No es redimensionable this.setLocation(100, 100); // Posicion desde la esquina superior izquierda del monitor this.setSize(new Dimension(500, 250)); // Dimensiones this.add(Lienzo); Lienzo.setBounds(10,10,450,240); Lienzo.start(); this.setVisible(true); } public static void main(String R[]) { new Linea1(); } // 3.- Captura del evento "cerrar ventana" protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } } class AreaDeDibujo extends Canvas implements Runnable { Thread Hilo; int x = 10; public void start( ) { if (Hilo == null) { Hilo = new Thread(this); Hilo.start( ); } } public void run( ) { while(x < 300) { try { Thread.sleep(500); } catch(InterruptedException r) { } x += 10; repaint(); } } public void paint(Graphics G) { G.clearRect(0, 0, 400, 250); G.drawString("RAFA", x, 10); } // public static void main(String a[]) { new Animacion(); } }