import java.awt.event.*;
import java.awt.Graphics;
import java.awt.Font;
import java.applet.Applet;
import java.awt.*;
import java.applet.*;


public class NervousText extends Applet implements Runnable, MouseListener
{
    String banner;		// The text to be displayed
    char bannerChars[];		// The same text as an array of characters
    Thread runner = null;	// The thread that is displaying the text
    boolean threadSuspended;	// True when thread suspended (via mouse click)

    public void init() 
    {
		banner = getParameter("text");
		if (banner == null)
		{
	    	banner = "HotJava";
		}
        int bannerLength = banner.length();
		bannerChars =  new char[bannerLength];
        banner.getChars(0, banner.length(), bannerChars, 0);
        threadSuspended = false;
		resize(15*(bannerLength + 1), 50);
		setFont(new Font("TimesRoman", Font.BOLD, 36));
		addMouseListener(this);
    }

    public void destroy()
    {
        removeMouseListener(this);
    }

    public void start()
    {
        runner = new Thread(this);
        runner.start();
    }

    public synchronized void stop()
    {
		runner = null;
        if (threadSuspended)
        {
            threadSuspended = false;
            notify();
        }
    }

    public void run()
    {
        Thread me = Thread.currentThread();
        while (runner == me)
        {
            try
            {
                Thread.sleep(100);
                synchronized(this)
                {
                    while (threadSuspended)
                    {
                        wait();
                    }
                }
            }
            catch (InterruptedException e)
            {
            
            }
            repaint();
        }
    }

    public void paint(Graphics g)
    {
        g.setPaintMode();
        for(int i=0, length = banner.length(); i<400/*length*/; i++)
        {
            int x = (int) (//10*Math.random() + 
            15*i);
            int y = (int) (//10*Math.random() + 
            36);
            //g.drawChars(bannerChars, i, 1, x, y);
            //g.draw3DRect(10, i, 60, i, true);
		 	g.drawOval(i, i, i, i);
		 	g.clearRect(i, i, i, i);
		 	repaint();
		 	setBackground(Color.cyan);
	     /*//g.drawString("Here are a selection of blank shapes.",20,40);
	     g.drawLine(20,40,200,40);
	     g.setColor(Color.blue);
	     g.drawLine(20,50,70,90);
	     g.setColor(Color.red);
	     g.drawRect(100,50,32,55);
	     g.setColor(Color.green);
	     g.drawOval(150,46,60,60);
	     g.setColor(Color.magenta);
	     g.drawArc(230,50,65,50,30,270);
	     g.setColor(Color.black);
	     //g.drawString("Here are the filled equivalents.",20,140);
	     g.drawLine(20,140,200,140);
	     g.setColor(Color.yellow);
	     g.fillRect(100,150,32,55);
	     g.setColor(Color.pink);
	     g.fillOval(150,146,60,60);
	     g.setColor(Color.darkGray);
	     g.fillArc(230,150,65,50,30,270);*/
		 	
		}
		 

    }

    public synchronized void mousePressed(MouseEvent e) {
        e.consume();
        threadSuspended = !threadSuspended;
        if (!threadSuspended)
            notify();
    }

    public void mouseReleased(MouseEvent e)
    {
    }

    public void mouseEntered(MouseEvent e)
    {
    }

    public void mouseExited(MouseEvent e)
    {
    }

    public void mouseClicked(MouseEvent e)
    {
    }

    public String getAppletInfo()
    {
        return "Title: NervousText\nAuthor: Daniel Wyszynski\nDisplays a text banner that jitters.";
    }

    public String[][] getParameterInfo()
    {
        String pinfo[][] =
        {
            {"text", "string", "Text to display"},
    	};
        return pinfo;
    }
    
}//class NervousText

