[My Resume] [Home]
CIS4850 Scrolling Project

This applet has the following functionality:

This is the source Code:

import java.awt.*;
/*******************************************************
*	This applet has the following functionality:   *
*	To stop the scrolling text at any moment:      *
*	   Double_click the left mouse button.         *
*	To start the scrolling text again:             *
*	   Double_click the left mouse button.         *
*	To change the font to a bigger size:           *
*	   Single click the right mouse button         *
*	To change the font back to its original font:  *
*	   Single click the right mouse button again.  *
********************************************************/

public class projThree extends java.applet.Applet 
	implements Runnable
{
  //Globals
  Thread runner;
		
  String msg[] = {"HomeStores has the best selection in Home Products",
	          "Decorative Fabrics:",
		  "Waverly Designs",
		  "Spectrum Fabrics",
		  "Western Fabrics",
		  "Rugs:",
		  "Area Rugs",
		  "Chinese Rugs",
		  "Hand made Rugs",
		  "Hardware:",
		  "Cutin Rods",
		  "Wood Poles",
		  "We also have magazines and books",
		  "Thanks for doing business with us!!"};
  Font f1;
  Font f2;
	
  int[] yPos = new int[msg.length];
  int xPos = 10;
  int Ymax, Xmax;
	
  int delay = 20;
  int decre =1;
  int yLast;
	
  int i;
  int countMouseDown = 1;
  int count = 1;			

  //responds to mouse clicks
  public boolean mouseDown(Event evt,int x,int y)
  {	
     //responce to single_right_mouse_clicks
     if(evt.metaDown() && evt.clickCount == 1 && countMouseDown == 1)
     {
	f2 = new Font("SansSerif",Font.BOLD,18);
	f1 = new Font("TimesRoman",Font.BOLD,14);
	countMouseDown = 0;
	return true;
     }
     //responce to single_right_mouse_clicks
     else if(evt.metaDown() && evt.clickCount == 1 && countMouseDown == 0)
     {
	f2 = new Font("SansSerif",Font.BOLD,12);
	f1 = new Font("TimesRoman",Font.PLAIN,10);
	countMouseDown = 1;
	return true;
     }
    //responce to left_double_mouse_clicks
    if((!evt.metaDown()) && evt.clickCount == 2 && count ==1)
    {
	//delay = 70;
	runner = null;
	count = 0;
	return true;
    }
    //responce to left_double_mouse_clicks
    else if((!evt.metaDown()) && evt.clickCount == 2 && count == 0)
    {
	//delay = 20;
	start();
	count = 1;
	return true;
    } 
   return true;
  }
	
  public  void init()
  {
    f1 = new Font("TimesRoman",Font.PLAIN,10);
    f2 = new Font("SansSerif",Font.BOLD,12);
		
    setBackground(Color.white);
		
    Xmax = size().width;
    Ymax = size().height;
		
    for(int j = 0; j < yPos.length; j++)
	yPos[j] = Ymax - 1 + (12 + 7) * j +decre;
  }
	
  public void paint(Graphics g)
  {
    for(i = 0; i < yPos.length; i++)
    {
	yPos[i] -= decre;					  
		
	g.setColor(Color.blue);
		  
	if(i==0||i==1||i==5||i==9||i==12||i==13)
	{
	    g.setFont(f2);
	    g.setColor(Color.black);
	}
	else
	{
	    g.setFont(f1);
	    g.setColor(Color.blue);
	}
			  	   
	g.drawString(msg[i],xPos,yPos[i]);
	}	
    }	
	
	
	
  public void start()
  {
    if(runner == null)
    {
	runner = new Thread(this);
	runner.start();
    }
  }
	
  public void stop()
  {
    if(runner !=null)
    {
	runner.stop();
	runner = null;
    }
  }
	
  void pause(int time)
  {
    try{ Thread.sleep(time);}
    catch(InterruptedException e){}
  }
	
  public void run()
  {
   while(runner != null)
   {
      repaint();
      pause(delay);
   
      if(yPos[yPos.length - 1] < 0)
      {
         Xmax = size().width;
       	 ymax = size().height;
         for(int k = 0; k < yPos.length; k++)
	         yPos[k] = Ymax - 1 + (12 + 7) * k +decre;
      }        //end for if
   }         //end forwhile loop
 }           //end forrun()

}            //end for MyLine
1