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

public class NervousText extends Applet implements Runnable, AdjustmentListener //, 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)
	int mag=1;
	int maxValue=255;
	int minValue=-255;
	int maxY=255;
	int hz=440;
	final double cvtDegToRad = Math.PI/180;
    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);
		
		setLayout(new BorderLayout() );
		Scrollbar sb = new Scrollbar(Scrollbar.HORIZONTAL);
		sb.setValue(1);
		sb.addAdjustmentListener(this);
		add(sb, BorderLayout.SOUTH);
    }
	public void adjustmentValueChanged(AdjustmentEvent ae) {
		mag = ae.getValue();
		if(mag==0)mag=1;
		repaint();
	}
	
	public void setMag(int m)
    {
    	mag=m;
    	//repaint();
    }
    public void setMax(int m)
    {
    	maxValue=m;
    	maxY=m;
    	repaint();
    }
    public void setMin(int m)
    {
    	minValue=m;
    	//repaint();
    }
    public void setHz(int m)
    {
    	hz=m;
    	//repaint();
    }
    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)
    {
    	int y, oldX, oldY;
		double radians;
		double degrees;
    	Dimension d = this.getSize();
    	int axis = (int)(d.height/2);
    	
    
    	
    	//int hz=360*10*2;
		//int [] sndBuffer = new int [hz];
		boolean forward=true;
		int inc=1, maxValue2=maxValue, minValue2=minValue, temp=minValue2;
		g.setPaintMode();
		//setBackground(Color.green);
		//for(int ii=0, length = banner.length(); ii<1; ii++)
       	//{
           	//
           	g.setColor(Color.black);
           	for(int i = 0; i < 60000; i++){
	           		double t = ((double)i)/1000.0d;
	           		g.drawOval( (int)(5*t),(int)(4.9*Math.pow(t, 2)) ,5,5);
	      			//repaint();
	      			waitMs(1);
	      			
	        }
		}   
	
	private void waitMs(int waitTime){
		long  initialTime = System.currentTimeMillis();
		while(System.currentTimeMillis() < initialTime+waitTime);
		return;
	}
	
    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: sndWaveForm Demo\nAuthor: RatJed\nNot much yet.";
    }
    public String[][] getParameterInfo()
    {
        String pinfo[][] =
        {
            {"text", "string", "Text to display"},
    	};
        return pinfo;
    }
}//class NervousText
