[My Resume] [Home]
CIS4850 Scrolling Project

This is the source Code:

import java.awt.Font;
import java.awt.Color;
import java.awt.Graphics;


public class MyLine2 extends java.applet.Applet implements Runnable
{
	
	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!!"};
					
	
	int[] yPos = new int[msg.length];
	int xPos = 10;
	int Ymax, Xmax;
	int delay = 100;
	int decre =1;
	int yLast;

	public  void init()
	{
		
		Xmax = size().width;
		Ymax = size().height;
		for(int i = 0; i < yPos.length; i++)
			yPos[i] = Ymax - 1 + (12 + 7) * i +decre;
	}
	
	public void paint(Graphics g)
	{
		int i;
		Font f1 = new Font("TimesRoman",Font.PLAIN,10);
		Font f2 = new Font("SansSerif",Font.BOLD,12);
		setBackground(Color.white);
		g.setColor(Color.blue);
		
		for(i = 0; i < yPos.length; i++)
		{
		   yPos[i] -= decre;
			
		   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(true)
	   {
	      repaint();
	      pause(delay);
	      if(yPos[yPos.length - 1] < 0)
	      {
		init();
				
	      }
	   }
	}
	
}


   
1