/**adWord(number).java by gregvan
 * RECOMMENDED SIZE: height 80, width 600
* you may change the words by modifying
* the html on your webpage... parameters
* pass what you want to say to the applet
*<applet code=artword(number).class
*height=80 width=600>
*<param name="sw" value="Stationary Words...">
*</applet>
**/


import java.applet.*;
import java.awt.*;

public class adword4 extends Applet implements Runnable
{
   
int rr,gg,bb;//color variables  
int r1=1; //color up-down counters
int g1=1;  
int b1=1;   
int x, y; //locations
int z;
int a;
int cx; // applet.width/4
int cy; // applet.height/4

int zz=1; //initial value of up-down counters
int xx=1;
int yy=1;
int aa=1;
String yourWords;
String yourWords1;
String moreWords;
String stationaryWords;        
        Thread    myRunner;


        Image     buffer;         
        Dimension appletSize;     
        Graphics  bufferGraphics;
        
        public void init()
        {
// get the words from the webpages html                


stationaryWords=getParameter("sw");
if (stationaryWords==null){stationaryWords="";} 
            
      setBackground(Color.black);
               
      appletSize = this.getSize();

      buffer = this.createImage(appletSize.width, appletSize.height);
      cx=appletSize.width/4;
      cy=appletSize.height/4;

      bufferGraphics = buffer.getGraphics();
        }

        public void start()
        {
                if (myRunner == null)
                { 
                      
                        myRunner = new Thread(this);
                        myRunner.start();
                }
        }

        public void run()
        {
             
                Thread  executingThread;
                                
                executingThread = Thread.currentThread();

                while (myRunner == executingThread)
                {
                  //new random numbers to start animation
	x=(int)(Math.random() *256);
	y=(int)(Math.random() *256);
	z=(int)(Math.random() *256);
	a=(int)(Math.random() *100);   
        rr=x;//random color 
        gg=y;
        bb=z;  

                        repaint();
                        try
                        {
              // sleep for 1 second (1000 msec = 1 sec)
                                Thread.sleep(100);
                        }
                        catch(InterruptedException e) 
                        {
                        } 

                        while (myRunner != null)
                        {
                               
                                repaint(); 
                                try
                                {
                     // pause for .1 second
                               Thread.sleep(100);  
                                }
                                catch (InterruptedException e) 
                                {
                                }
                        }  
                }  //end while thread executing
        }

        //suspends execution when user leaves page
        public void stop()
        { 
                if (myRunner != null)
                {
                        myRunner = null;
                }
        }

        public void update(Graphics g)
        {
                paint(g);
        }


        public void paint(Graphics g)
        {
        for(int i=0; i<5;i++)
         {
//color changer 
        rr=rr+r1;
        if(rr>250){r1=-3;}
        if(rr<5){r1=3;}
        gg=gg+g1;
        if(gg>251){g1=-1;}
        if(gg<4){g1=1;}
        bb=bb+b1;
        if(bb>249){b1=-2;}
        if(bb<6){b1=2;}
//move the location of the words
//classic up-down counters
//we use x and z to define where to start the lines
//sometimes, zz=-1 and xx=1
//then the words stop moving...
//y and a are used for vertical position...

        z=z+zz;
        if(z>300+cy){zz=-1;}
        if(z<-cy){zz=1;}
        a=a+aa;
        if(a>cy+10){aa=-1;}
        if(a<-(cy+10)){aa=1;}
        x=x+xx;
        if(x>300){xx=-2;}
        if(x<-cy){xx=1;}
        y=y+yy;
        if(y>cy+cy){yy=-2;}  
        if(y<-(cy+cy)){yy=1;} 


Color eNew = new Color(rr, gg, bb);
   bufferGraphics.setColor(eNew);
   bufferGraphics.setFont(new Font("Serif",Font.PLAIN,60));

//use the parameters sent from the webpage

bufferGraphics.drawString(""+stationaryWords ,15,65); 
Color gNew = new Color(gg,256-bb, 256-rr);
   bufferGraphics.setColor(gNew);
bufferGraphics.drawLine(z+x+a-y,0,z+x-a+y,80);

}//end of for loop
// [1]"then copy the off-screen buffer onto the screen"
              
        g.drawImage(buffer, 0, 0, this);
        }
}//end of program

