THREAD_SimpleAnimationApp.java



// MUESTRA ASTERISCOS COMO SI FUERAN PUNTOS SUSPENSIVOS
import java.awt.*; 
import java.awt.event.*;

public class SimpleAnimationApp extends Frame {

	Animacion A = new Animacion();
    int screenWidth = 800; 
    int screenHeight = 800; 

    public static void main(String args[]) {SimpleAnimationApp app = new SimpleAnimationApp();   } 

    public SimpleAnimationApp() {
	super("Simple Animation"); 
	setup(); 
	setSize(screenWidth,screenHeight); 
	addWindowListener(new WindowEventHandler()); 
	setVisible(true);
	add(A); A.setBounds(0,0, 500, 500);

    }

    void setup() { 
	setupMenuBar(); 
	setFont(new Font("default",Font.BOLD,18));
    } 
    void setupMenuBar() {
	MenuBar menuBar = new MenuBar(); 
	Menu fileMenu = new Menu("File"); 
	MenuItem fileExit = new MenuItem("Exit"); 
	fileExit.addActionListener(new MenuItemHandler()); 
	fileMenu.add(fileExit);
	menuBar.add(fileMenu);
	setMenuBar(menuBar);
    }

    class MenuItemHandler implements ActionListener, ItemListener {
	public void actionPerformed(ActionEvent ev){ 
	    String s=ev.getActionCommand(); 
	    if(s=="Exit"){
		System.exit(0);
	    }
	}
	public void itemStateChanged(ItemEvent e){
	}
    } 
    class WindowEventHandler extends WindowAdapter {
	public void windowClosing(WindowEvent e){ 
	    System.exit(0);
	} 
    }
}

class Animacion extends Panel implements Runnable
{
	Thread animation; int frameDelay = 100;
	int F=0;
	String frames[] = {"*","**","***","****","*****","****","***","**","*"};

	public void paint(Graphics g)
	{
		 g.setColor(Color.blue);
		g.fillRect(0,0,200,200);
		g.setColor(Color.white);
		g.drawString(frames[F],60,60);
	}

    public void run() {
        do {
                repaint();
                try { Thread.sleep( 500 ); }catch(InterruptedException ex){ }
                ++F;
                if ( F > 8) F = 0;


        } while (true);
    }

	public Animacion()
	{
		animation = new Thread(this);
	        animation.start();
	}
}