Important alert: (current site time 7/15/2013 4:14:08 PM EDT)
 

VB icon

Easy simple scrolling banner applet

Email
Submitted on: 9/13/2000 4:05:33 PM
By: Jonathan Barker  
Level: Beginner
User Rating: Unrated
Compatibility: Java (JDK 1.1)
Views: 46153
 
     A Very simple java scroller Applet. Simply change the internals to make it do what you want!
 

HTML:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//HTML for :Easy simple scrolling banner applet
//**************************************
<APPLET CODE="scroll.class" WIDTH=640 HEIGHT=14>
<PARAM NAME="message" VALUE="Hello!">
</APPLET>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Easy simple scrolling banner applet
// Description:A Very simple java scroller Applet. Simply change the internals to make it do what you want!
// By: Jonathan Barker
//
// Inputs:Put a param called message for your message...
//
// Assumes:Compile with sun's javac 1.1 compiler.
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1957&lngWId=2//for details.//**************************************

// Cute little scrolling banner...
import java.applet.Applet;
import java.awt.*;
public class scroll extends Applet implements Runnable
{
String message;
Image messageimage;
Graphics messagegraphics;
Thread me;
int xpos;
int ypos;
int textwidth;
	public void init()
	{
		setBackground(Color.black); // Background color of applet. Try Color.white or Color.red and so on...
		message = getParameter("message");
		messageimage = createImage(size().width, size().height);
		messagegraphics = messageimage.getGraphics();
		xpos = size().width + 10;
		ypos = 12; // position to look right
		textwidth = 7 * message.length();
		me = new Thread(this);
		me.start();
	}
	public void run()
	{
		while(true) {
			xpos--;
			if (xpos < -textwidth)
			{
				xpos = size().width + 10;			
			}
			try
			{
			Thread.sleep(10);
			}
			catch (InterruptedException _ex) { }
			repaint();
		}
	}
	public void paint(Graphics g)
	{
		messagegraphics.setColor(Color.black); // Background colour again
		messagegraphics.fillRect(0,0,size().width + 1, size().height + 1);
		messagegraphics.setColor(Color.white); // Text colour here
try
{
 messagegraphics.setFont(new Font("Arial",0,10)); // change font or font size (Fontname, 0, Size)
}
catch(NullPointerException _ex) { }
		messagegraphics.drawString(message, xpos, ypos);
		g.drawImage(messageimage, 0, 0, this);
	}
	
	public void update(Graphics g)
	{
		paint(g);
	}
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

1/11/2003 1:31:00 PMSimon A Scott

The method size() is deprecated
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.