/** Use JWS to modify MyApplet14.java (previously AnimatorApplet6.java) by adding 
 ** another, fourth, "Lost in Space?" scenario. Your scenario should include a 
 ** different background image choosen from the Astronomy Picture of the Day Archive 
 ** at: http://antwrp.gsfc.nasa.gov/apod/archivepix.html. In addition, you should 
 ** include a rocketship image moving in a different way with a different scrolling 
 ** text. After your scenario completes, it should loop smoothly back to the first 
 ** scenario. Also, edit MyApplet14.html in the project directory, both to run the
 ** MyApplet14.class file you create, and so that everything looks nice and works 
 ** properly.                                                                     **/

/** USE EXISTING JAVA CLASSES **/

import java.awt.*;
import java.applet.Applet;

/** EXTEND THE JAVA APPLET CLASS AND IMPLEMENT THE RUNNABLE INTERFACE **/

public class AllanApplet14 extends Applet implements Runnable
   {int frameNumber = -1;                
    int delay;                          
    Thread animatorThread;
    boolean frozen = false;
    Font waitfont=new Font("TimesRoman",Font.BOLD,14);
    FontMetrics waitfontm = getFontMetrics(waitfont);
    String waitstr1, waitstr2, waitstr3 = "";
    Font kirkfont=new Font("TimesRoman",Font.PLAIN,10);
    FontMetrics kirkfontm = getFontMetrics(kirkfont);
    String shipstr = "";
    String kirkstr = "";
    String kirkstrpad = "                                                    ";
    Font titlefont=new Font("TimesRoman",Font.BOLD,24);
    FontMetrics titlefontm = getFontMetrics(titlefont);
    String titlestr = "";
    Color starblue = new Color(0,100,255);
    Thread frameThread; 
     
    Font font=new Font("TimesRoman",Font.BOLD,30); 
    String framestr = ""; 
    Dimension preImageDim;               // Define preImage variables needed to
    Image preImage;                      // create the offscreen copy of the image
    Graphics preImageGraphics;           // we want to paint on the screen.
    
    
    Image backgroundstarImage[];                    
    Image background1;
    Image background2;
    Image background3;
    Image background4;
    Image background5;
    Image PleiadesClusterImage;
    Image starbackground;
    Image kirk;                 
    Image picard;
    Image sisko;
    Image rocketshipImage;
    Image torpedo;
    Image enterprisea1;
    Image enterprisea2;
    Image enterprisee1;
    Image enterprisee2;
    Image defiant;
    Image defiant2;
    Image explosion;
    Image nothing;
    Image fire1;
    Image fire2;
    Image fire3;
    Image fire4;
    Image fire5;
    Image fire6;
    
    MediaTracker tracker;                
    int backNumber = 0;
    int kirkstrIndex = 0;
    int xspeedUp = 0;
    int yspeedUp = 0;

    /** INITIALIZE THE APPLET **/

    public void init()
       {setBackground(Color.black);
	String str;
        int fps = 10;                      // Define the default fps (frames per second).
        str = getParameter("fps");         // Possibly, get HTML string specifying the
        try                                // fps.
         {if (str != null)
           {fps = Integer.parseInt(str);}  // If possible, convert HTML fps to an
          }                                // integer.
        catch (Exception e) {}             // In case the try caused something strange.
        delay = (fps > 0) ? (1000/fps): 100; // Convert fps to the milisecond delay
                                             // time between frames.			     
	backgroundstarImage = new Image[6];
        tracker = new MediaTracker(this);    // Spawn the tracker background thread(s)
	background1 = getImage(getCodeBase(),"images/background1.JPG");
	tracker.addImage(background1,0);
	background2 = getImage(getCodeBase(),"images/background1.JPG");
	tracker.addImage(background2,0);
	background3 = getImage(getCodeBase(),"images/starbackground.gif");
	tracker.addImage(background3,0);
	background4 = getImage(getCodeBase(),"images/starbackground.gif");
	tracker.addImage(background4,0);
	background5 = getImage(getCodeBase(),"images/starbackground.gif");
	tracker.addImage(background5,0);
	
	backgroundstarImage[0] = background1;
	tracker.addImage(backgroundstarImage[0],0);
	backgroundstarImage[1] = background2;
	tracker.addImage(backgroundstarImage[1],0);
	backgroundstarImage[2] = background3;
	tracker.addImage(backgroundstarImage[2],0);
	backgroundstarImage[3] = background4;
	tracker.addImage(backgroundstarImage[3],0);
	backgroundstarImage[4] = background4;
	tracker.addImage(backgroundstarImage[4],0);
	backgroundstarImage[5] = background5;
	tracker.addImage(backgroundstarImage[5],0);
	
	nothing = getImage(getCodeBase(),"images/nothing.gif");
	tracker.addImage(nothing,0);
	torpedo = getImage(getCodeBase(),"images/torpedo.GIF");
	tracker.addImage(torpedo,0);
	defiant2 = getImage(getCodeBase(),"images/defiant2.GIF");
	tracker.addImage(defiant2,0);
	fire1 = getImage(getCodeBase(),"images/fire1.gif");
	tracker.addImage(fire1,0);
	fire2 = getImage(getCodeBase(),"images/fire2.gif");
	tracker.addImage(fire2,0);
	fire3 = getImage(getCodeBase(),"images/fire3.gif");
	tracker.addImage(fire3,0);
	fire4 = getImage(getCodeBase(),"images/fire4.gif");
	tracker.addImage(fire4,0);
	fire5 = getImage(getCodeBase(),"images/fire5.gif");
	tracker.addImage(fire5,0);
	fire6 = getImage(getCodeBase(),"images/fire6.gif");
	tracker.addImage(fire6,0);
	picard = getImage(getCodeBase(),"images/picard.jpg");
	tracker.addImage(picard,0);    
	sisko = getImage(getCodeBase(),"images/sisko.gif");
	tracker.addImage(sisko,0);
	kirk = getImage(getCodeBase(),"images/kirk.jpg");
	tracker.addImage(kirk,0);
	explosion = getImage(getCodeBase(),"images/explosion.GIF");
	tracker.addImage(explosion,0);
	enterprisea1 = getImage(getCodeBase(),"images/enterprisea1.gif");
	tracker.addImage(enterprisea1,0);
	enterprisea2 = getImage(getCodeBase(),"images/enterprisea2.gif");
	tracker.addImage(enterprisea2,0);
	enterprisee2 = getImage(getCodeBase(),"images/enterprisee2.gif");
	tracker.addImage(enterprisee2,0);
	enterprisee1 = getImage(getCodeBase(),"images/enterprisee1.gif");
	tracker.addImage(enterprisee1,0);
	}  

    /** CLICK TO START OR STOP THE APPLET **/

    public boolean mouseDown(Event e, int x, int y)
       {if (frozen)
         {frozen = false;
          start();}
        else
         {frozen = true;
          animatorThread = null;           // Instead of calling stop() here, since
	  }                                // stop() now nullifies our preImage context,
        return true;                       // nullify only the animation thread in case
        }                                  // we want to build on our current preImage.

    /** GENERATE AND/OR START THE ANIMATION THREAD **/

    public void start()
       {if (frozen) { }                    // The animation is supposed to stay frozen.
        else                               // Otherwise, generate and/or start the
         {if (animatorThread == null)      // animation thread. Apparently, if run
           {animatorThread = new Thread(this);}  // breaks after catching an exception,
          animatorThread.start();                // the animatorThread though not null
          }                                      // will still need to be restarted.
        }

    /** CREATE AND DISPLAY FRAMES OF THE ANIMATION THREAD **/

    public void run()
       {try                                              // Start loading the images and
	 {tracker.waitForAll();}                         // wait until done before starting   
        catch (InterruptedException e) {}                // the animation.
        Thread.currentThread().setPriority(Thread.MIN_PRIORITY); // Set the priority low.
        long startTime = System.currentTimeMillis();             // Remember start time.
        while (Thread.currentThread() == animatorThread)         // The animation loop.
           {frameNumber++;                               // Advance the frame number.
            repaint();                                   // Display the frame.
            try                                          // Sleep for the delay period.
             {startTime += delay;
              Thread.sleep(Math.max(0,
                                    startTime-System.currentTimeMillis()));
              }
            catch (InterruptedException e) {break;}     // In case the try caused
            }                                           // something strange, exit
        }                                               // the while loop.


    /** CREATE THE CURRENT FRAME OF THE ANIMATION THREAD **/
    
    public void paint(Graphics g)         // This technique of painting by calling
     {if (!frozen) update(g);}            // update, prevents the default (and hidden)  
					  // behavior of update, and instead allows
    public void update(Graphics g)        // the creation of an offscreen preImage 
     {Dimension d = size();              // preImage before painting the screen.  
      if (!tracker.checkAll())                       // If the images aren't all
       {g.clearRect(0, 0, d.width, d.height);        // loaded, then clear the 
	g.setColor(starblue);
	g.setFont(waitfont);  
	waitstr1 = "Star Trek: Battle of the Captains' Egos";
	waitstr2 = "Loading images, please wait...  Depending upon your computer ";
	waitstr3 = "and/or your connection speed, this may take several minutes...";
	g.drawString(waitstr1,                                    
	             (d.width - waitfontm.stringWidth(waitstr1))/2, 
		      d.height/2);    
	g.drawString(waitstr2,                                    
	             (d.width - waitfontm.stringWidth(waitstr2))/2, 
		      (d.height/2) + waitfontm.getHeight());	                                  
        g.drawString(waitstr3,                                    
	             (d.width - waitfontm.stringWidth(waitstr3))/2, 
		      (d.height/2) + (waitfontm.getHeight() + waitfontm.getHeight()));                                
	}
      else	       	               
       {if ((preImageGraphics == null) ||               // When all images are loaded, 
	    (d.width != preImageDim.width) ||           // compare the current applet
	    (d.height != preImageDim.height))           // viewing size to our preImage,
	     {preImageDim = d;                          // and if different, resize our 
	      preImage = createImage(d.width,d.height); // next preImage.
	      preImageGraphics = preImage.getGraphics();
	      }                                     
	preImageGraphics.setColor(getBackground());      // Clear the previous preImage
	preImageGraphics.fillRect(0,0,d.width,d.height); // by filling with the current
							 // background.
	                                                             // something strange, exit 
        int kirkWidth = kirk.getWidth(this);                                                                   // the while loop. 
	int defiant2Width = defiant2.getWidth(this);   // Get rocketship image 
	int defiant2Height = defiant2.getHeight(this); // dimensions.  
	int enterprisea1Width = enterprisea1.getWidth(this);   // Get rocketship image 
	int enterprisea1Height = enterprisea1.getHeight(this); // dimensions.  
	int enterprisea2Width = enterprisea2.getWidth(this);   // Get rocketship image 
	int enterprisea2Height = enterprisea2.getHeight(this); // dimensions.    
	int enterprisee2Width = enterprisee2.getWidth(this);   // Get rocketship image 
	int enterprisee2Height = enterprisee2.getHeight(this);
	int enterprisee1Width = enterprisee1.getWidth(this);   // Get rocketship image 
	int enterprisee1Height = enterprisee1.getHeight(this);
	int xscrollDistance = d.width + enterprisea2Width;                         
	int yscrollDistance = d.height + enterprisea2Height;  
	
	int xscrollPosition = 0;
	int yscrollPosition = 0;
	int cycle = 0;
	
	preImageGraphics.drawImage(                          
	   backgroundstarImage[backNumber],              // Select background image.     
	   0,0,d.width,d.height,Color.black,this);       // Position and size image,     
							 // and set background color.
	preImageGraphics.setFont(titlefont);                  
	preImageGraphics.setColor(starblue);  
	preImageGraphics.drawString(
	   "Biggest Ego ?  ",
	   d.width - titlefontm.stringWidth("Biggest Ego ?  "),
	   titlefontm.getAscent());		
//backNumber = 3;   
	if (backNumber == 0)                                   // Paint on background 0.
	  
	  {yscrollPosition = (frameNumber % yscrollDistance) - enterprisea2Height/2 + yspeedUp*10;
	  //while ((yscrollPosition >= (d.height/6) +10)&&(yscrollPosition < (d.height/3) +10))
	   if (yscrollPosition >= (d.height/6) +10) yspeedUp++;
	   if (yscrollPosition >= (d.height/3) +10) xspeedUp++;      // Go to warp speed.
	   xscrollPosition = 
	      (frameNumber % xscrollDistance) - enterprisea2Width/2 + xspeedUp*30;
	   preImageGraphics.drawImage(kirk,0,(d.height - 150),this); 
	   preImageGraphics.drawImage(
	      enterprisee2,
	      (d.width - enterprisee2Width),
	      (d.height - enterprisee2Height),this);
	   preImageGraphics.drawImage(
	      enterprisea2,
	      xscrollPosition,
	      yscrollPosition,this);	
	  preImageGraphics.setColor(Color.red);	
	  if ((yscrollPosition >= (d.height/3) +10)&&(xscrollPosition <= d.width - 200)) 
	   {preImageGraphics.drawLine(xscrollPosition + 120, yscrollPosition + 50, 
				    (d.width - enterprisee2Width + 20), (d.height - enterprisee2Height + 33));
	 // if (yscrollPosition >= (d.height/3) +10) 
	    preImageGraphics.drawImage(explosion, (d.width - enterprisee2Width + 5), (d.height - enterprisee2Height + 25),this);
	    }
	 if ((yscrollPosition >= (d.height/3) +10)&&(xscrollPosition > d.width - 200))   
	  cycle++;  
	    	  	 
	// preImageGraphics.setFont(font);                           // background color (magenta), 
         preImageGraphics.setColor(starblue); 	
	 preImageGraphics.setFont(kirkfont);
	   kirkstr = "          Picard, Your nothing but a 24th century Mr. Clean !!";
	   kirkstr += kirkstrpad + kirkstrpad + kirkstrpad + kirkstrpad;                  // Pad shipstr with blanks.
	   if (yscrollPosition > 0)
	    {preImageGraphics.drawString(
	     kirkstr.substring(kirkstrIndex,kirkstrIndex + 21), // Compute current substring
	     0, d.height - 10);	
	   if (frameNumber % 2 == 0) kirkstrIndex++;          // Slow down shipstr display.
	   if (kirkstrIndex + 15 == kirkstr.length()) kirkstrIndex = 0; // Start over at 
	     }	
	                                                          // end of shipstr.
	  if (xscrollPosition >= d.width) 
	      {frameNumber = -1; 
	       backNumber = 1;
	       kirkstrIndex = 0;
	       yspeedUp = 0;
	       xspeedUp = 0;
	       }
	   }
	
    else if (backNumber == 1)                               // Paint on background 1.
	 {yscrollPosition = (d.height/2) - (frameNumber % yscrollDistance);
	  if (yscrollPosition <= .1*d.height) xspeedUp++;	 
	   xscrollPosition = 
	        (frameNumber % xscrollDistance) - enterprisea2Width + xspeedUp*50;
	 preImageGraphics.drawImage(picard,0,d.height - 150,this);
	 preImageGraphics.drawImage(
	      enterprisee1,
	      xscrollPosition,
	      (yscrollPosition + 15),this);	
	 preImageGraphics.drawImage(enterprisea1, (d.width - enterprisea1Width), (d.height - enterprisea1Height),this);	
	 preImageGraphics.setColor(Color.red);
	 if ((xscrollPosition >= 65) && (xscrollPosition <= 300))
	   preImageGraphics.drawLine(xscrollPosition + 150, yscrollPosition + 50, 
	   (d.width - enterprisea1Width + 20), (d.height - enterprisea1Height + 33));
	 if ((xscrollPosition >= 65) && (xscrollPosition <= 300))
	   preImageGraphics.drawImage(explosion, (d.width - enterprisea1Width + 5), (d.height - enterprisea1Height + 18),this);
	
	preImageGraphics.setFont(font);                           // background color (magenta), 
        preImageGraphics.setColor(starblue);  
	preImageGraphics.setFont(kirkfont);
	   kirkstr = "                              Kirk, you're an old fogy who wears a rug! Time for you to retire !!";
	   kirkstr += kirkstrpad + kirkstrpad + kirkstrpad + kirkstrpad;  //ADDED EXTRA PADDING HERE // Pad shipstr with blanks.
	   if (yscrollPosition > 0)
	    {preImageGraphics.drawString(
	     kirkstr.substring(kirkstrIndex,kirkstrIndex + 21), // Compute current substring
	     0,d.height - 10);	
	     if (frameNumber % 2 == 0) kirkstrIndex++;          // Slow down shipstr display.
	     if (kirkstrIndex + 15 == kirkstr.length()) kirkstrIndex = 0; // Start over at 
	     }	                                                          // end of shipstr.
	   if (xscrollPosition >= d.width)                      // Setup for next background.
	    {frameNumber = -1; 
	     backNumber = 2;
	     kirkstrIndex = 0;
	     xspeedUp = 0;
	     }
	   }
	
    else if (backNumber == 2)                               // Paint on background 2.
	 {yscrollPosition = (frameNumber % yscrollDistance) - defiant2Height/2;
	   if (yscrollPosition >= (d.height/3)) xspeedUp++;      // Go to warp speed.
	   xscrollPosition = 
	      (frameNumber % xscrollDistance) - defiant2Width/2 + xspeedUp*30;
	   preImageGraphics.drawImage(sisko,0,(d.height - 150), this); 
	   preImageGraphics.drawImage(defiant2, xscrollPosition, yscrollPosition,this);	
	   if (yscrollPosition >= (d.height/3))
	    {preImageGraphics.drawImage(torpedo, 170, xscrollPosition, this);
	     preImageGraphics.drawImage(torpedo, 239, (xscrollPosition + 90), this);
	    }  //ADDED THIS BRACE
	preImageGraphics.setFont(font);                           // background color (magenta), 
       	preImageGraphics.setColor(starblue);  
	preImageGraphics.setFont(kirkfont);
	   kirkstr = "        Gentlemen, Starfleet grows weary of this bickering, and sent Sisko to settle it....";
	   kirkstr += kirkstrpad + kirkstrpad + kirkstrpad + kirkstrpad;                  // Pad shipstr with blanks.
	   if (yscrollPosition > 0)
	    {preImageGraphics.drawString(
	     kirkstr.substring(kirkstrIndex,kirkstrIndex + 21), // Compute current substring
	     0,d.height - 10);	
	     if (frameNumber % 2 == 0) kirkstrIndex++;          // Slow down shipstr display.
	     if (kirkstrIndex + 15 == kirkstr.length()) kirkstrIndex = 0; // Start over at 
	     }  //ADDED THIS BRACE	 
	  if (xscrollPosition >= d.width)                      // Setup for next background. 
	   {frameNumber = -1; 
	    backNumber = 3;
	    kirkstrIndex = 0; 
	    xspeedUp = 0;
	    yspeedUp = 0;
	    } 
	}                                               
	
    else if (backNumber == 3)                               // Paint on background 2.
	 {yscrollPosition = (frameNumber % yscrollDistance) - defiant2Height;
	   if (yscrollPosition <= (1)) xspeedUp++;      // Go to warp speed.
	   xscrollPosition = 
	      (frameNumber % xscrollDistance) - defiant2Width + xspeedUp*30;
	   preImageGraphics.drawImage(enterprisea2, 10, 200, this);
	    preImageGraphics.drawImage(enterprisee1, 225, 210, this); 
	   preImageGraphics.drawImage(nothing, xscrollPosition, 1, this);	
	  if (xscrollPosition <= (220))
	   { preImageGraphics.drawImage(torpedo, 170, xscrollPosition, this);
	    preImageGraphics.drawImage(torpedo, 300, (xscrollPosition + 90), this);  
	    } //ADDED THIS BRACE & ITS PAIR ABOVE
	  	 
	  
	  if (xscrollPosition >= d.width)                      // Setup for next background. 
	   {frameNumber = -1; 
	    backNumber = 4;
	    kirkstrIndex = 0;
	    xspeedUp = 0;
	    yspeedUp = 0;
	    } 
	  }  
	  
	  
    else if (backNumber == 4)                               // Paint on background 2.
	 {yscrollPosition = (frameNumber % yscrollDistance) - defiant2Height;
	   if (yscrollPosition <= (1)) xspeedUp++;      // Go to warp speed.
	   xscrollPosition = 
	      (frameNumber % xscrollDistance) - defiant2Width + xspeedUp*30;
	      
	       preImageGraphics.drawImage(fire1, 10,200, this); 
	        preImageGraphics.drawImage(fire1, 225, 210, this); 
	   preImageGraphics.drawImage(enterprisea2, 10, 200, this);
	    preImageGraphics.drawImage(enterprisee1, 225, 210, this); 
	   preImageGraphics.drawImage(nothing, xscrollPosition, 1, this);	
	if (xscrollPosition <= 20)    
	//if ((xscrollPosition >= 1) && (xscrollPosition <= 20))
	    preImageGraphics.drawImage(fire1, 10,200, this); 
	if ((xscrollPosition >= 21) && (xscrollPosition <= 40))
	    preImageGraphics.drawImage(fire2, 10,200, this);    
	if ((xscrollPosition >= 41) && (xscrollPosition <= 60))
	    preImageGraphics.drawImage(fire3, 10,200, this); 
	if ((xscrollPosition >= 61) && (xscrollPosition <= 80))
	    preImageGraphics.drawImage(fire4, 10,200, this);  
	if ((xscrollPosition >= 81) && (xscrollPosition <= 100))
	    preImageGraphics.drawImage(fire5, 10,200, this); 
	if ((xscrollPosition >= 101) && (xscrollPosition <= 120))
	    preImageGraphics.drawImage(fire6, 10,200, this);    
	if ((xscrollPosition >= 121) && (xscrollPosition <=140))
	    preImageGraphics.drawImage(fire1, 10,200, this); 
	if ((xscrollPosition >= 141) && (xscrollPosition <= 160))
	    preImageGraphics.drawImage(fire2, 10,200, this);     
	if ((xscrollPosition >= 161) && (xscrollPosition <= 180))
	    preImageGraphics.drawImage(fire3, 10,200, this); 
	if ((xscrollPosition >= 181) && (xscrollPosition <= 200))
	    preImageGraphics.drawImage(fire4, 10,200, this);  
	if ((xscrollPosition >= 201) && (xscrollPosition <= 220))
	    preImageGraphics.drawImage(fire5, 10,200, this); 
	if ((xscrollPosition >= 221) && (xscrollPosition <= 240))
	    preImageGraphics.drawImage(fire6, 10,200, this);         
	if ((xscrollPosition >= 241) && (xscrollPosition <= 260))
	    preImageGraphics.drawImage(fire1, 10,200, this); 
	if ((xscrollPosition >= 261) && (xscrollPosition <= 280))
	    preImageGraphics.drawImage(fire2, 10,200, this);     
	if ((xscrollPosition >= 301) && (xscrollPosition <= 320))
	    preImageGraphics.drawImage(fire3, 10,200, this); 
	if ((xscrollPosition >= 321) && (xscrollPosition <= 341))
	    preImageGraphics.drawImage(fire4, 10,200, this);  
	if ((xscrollPosition >= 361) && (xscrollPosition <= 380))
	    preImageGraphics.drawImage(fire5, 10,200, this); 
	if ((xscrollPosition >= 381) && (xscrollPosition <= 400))
	    preImageGraphics.drawImage(fire6, 10,200, this);    
	if ((xscrollPosition >= 401) && (xscrollPosition <=420))
	    preImageGraphics.drawImage(fire1, 10,200, this); 
	if ((xscrollPosition >= 421) && (xscrollPosition <= 440))
	    preImageGraphics.drawImage(fire2, 10,200, this);     
	if ((xscrollPosition >= 441) && (xscrollPosition <= 460))
	    preImageGraphics.drawImage(fire3, 10,200, this); 
	if ((xscrollPosition >= 461) && (xscrollPosition <= 480))
	    preImageGraphics.drawImage(fire4, 10,200, this);  
	if ((xscrollPosition >= 481) && (xscrollPosition <= 500))
	    preImageGraphics.drawImage(fire5, 10,200, this); 
	    
	if (xscrollPosition <= 20)        
	//if ((xscrollPosition >= 1) && (xscrollPosition <= 20))
	    preImageGraphics.drawImage(fire1, 225, 210, this); 
	if ((xscrollPosition >= 21) && (xscrollPosition <= 40))
	    preImageGraphics.drawImage(fire2, 225, 210, this);     
	if ((xscrollPosition >= 41) && (xscrollPosition <= 60))
	    preImageGraphics.drawImage(fire3, 225, 210, this); 
	if ((xscrollPosition >= 61) && (xscrollPosition <= 80))
	    preImageGraphics.drawImage(fire4, 225, 210, this);  
	if ((xscrollPosition >= 81) && (xscrollPosition <= 100))
	    preImageGraphics.drawImage(fire5, 225, 210, this); 
	if ((xscrollPosition >= 101) && (xscrollPosition <= 120))
	    preImageGraphics.drawImage(fire6, 225, 210, this);    
	if ((xscrollPosition >= 121) && (xscrollPosition <=140))
	    preImageGraphics.drawImage(fire1, 225, 210, this); 
	if ((xscrollPosition >= 141) && (xscrollPosition <= 160))
	    preImageGraphics.drawImage(fire2, 225, 210, this);     
	if ((xscrollPosition >= 161) && (xscrollPosition <= 180))
	    preImageGraphics.drawImage(fire3, 225, 210, this); 
	if ((xscrollPosition >= 181) && (xscrollPosition <= 200))
	    preImageGraphics.drawImage(fire4, 225, 210, this);  
	if ((xscrollPosition >= 201) && (xscrollPosition <= 220))
	    preImageGraphics.drawImage(fire5, 225, 210, this); 
	if ((xscrollPosition >= 221) && (xscrollPosition <= 240))
	    preImageGraphics.drawImage(fire6, 225, 210, this);         
	if ((xscrollPosition >= 241) && (xscrollPosition <= 260))
	    preImageGraphics.drawImage(fire1, 225, 210, this); 
	if ((xscrollPosition >= 261) && (xscrollPosition <= 280))
	    preImageGraphics.drawImage(fire2, 225, 210, this);     
	if ((xscrollPosition >= 301) && (xscrollPosition <= 320))
	    preImageGraphics.drawImage(fire3, 225, 210, this); 
	if ((xscrollPosition >= 321) && (xscrollPosition <= 341))
	    preImageGraphics.drawImage(fire4, 225, 210, this);  
	if ((xscrollPosition >= 361) && (xscrollPosition <= 380))
	    preImageGraphics.drawImage(fire5, 225, 210, this); 
	if ((xscrollPosition >= 381) && (xscrollPosition <= 400))
	    preImageGraphics.drawImage(fire6, 225, 210, this);    
	if ((xscrollPosition >= 401) && (xscrollPosition <=420))
	    preImageGraphics.drawImage(fire1, 225, 210, this); 
	if ((xscrollPosition >= 421) && (xscrollPosition <= 440))
	    preImageGraphics.drawImage(fire2, 225, 210, this);     
	if ((xscrollPosition >= 441) && (xscrollPosition <= 460))
	    preImageGraphics.drawImage(fire3, 225, 210, this); 
	if ((xscrollPosition >= 461) && (xscrollPosition <= 480))
	    preImageGraphics.drawImage(fire4, 225, 210, this);  
	if ((xscrollPosition >= 481) && (xscrollPosition <= 500))
	    preImageGraphics.drawImage(fire5, 225, 210, this); 	     
	 //REMOVED THIS BRACE }    	 
	  
	  if (xscrollPosition >= d.width)                      // Setup for next background. 
	   {frameNumber = -1; 
	    backNumber = 5;
	    kirkstrIndex = 0;
	    xspeedUp = 0;
	    yspeedUp = 0;
	     }
	    } 					 						 // Offscreen preImage completed.
	else if (backNumber == 5)                               // Paint on background 2.
	 {yscrollPosition = (frameNumber % yscrollDistance) - defiant2Height;
	   if (yscrollPosition <= (1)) xspeedUp++;      // Go to warp speed.
	   xscrollPosition = 
	      (frameNumber % xscrollDistance) - defiant2Width + xspeedUp*30;
	  // preImageGraphics.drawImage(enterprisea2, 10, 200, this);
	 //   preImageGraphics.drawImage(enterprisee1, 225, 210, this); 
	   preImageGraphics.drawImage(nothing, xscrollPosition, 1, this);	 
	 if (xscrollPosition >= d.width)                      // Setup for next background. 
	   {frameNumber = -1; 
	    backNumber = 0;
	    kirkstrIndex = 0;
	    xspeedUp = 0;
	    yspeedUp = 0;
	     }
	    } 				
	g.drawImage(preImage,0,0,this);	                // Paint preImage on the screen.
	} 
       
    }
    /** STOP THE ANIMATION THREAD **/

    public void stop() 
      {animatorThread = null;     // The user either clicked to stop or left the page,
       preImageGraphics = null;   // so wipe out the current thread and preImage context.
       preImage = null;
       }	
    }