The marquee applet in JAVA

A classic example of visual effects used on the web. 

 import java.applet.*;
import java.awt.*;
<applet code="marquee" width = 300 height = 200>

public class marquee extends Applet implements Runnable{
String msg = " Watch Me Scroll Across ";
Thread t = null;
int state;
boolean stopFlag;

public void init(){

public void start(){
t = new Thread (this);
stopFlag = false;
public void run(){
char ch;

for( ; ; ) {
try {
ch = msg.charAt(0);
msg = msg.substring(1, msg.length());
msg +=ch;
} catch (InterruptedException e) {}

public void stop () {
stopFlag = true;
t = null;

public void paint(Graphics g){
g.drawString (msg,50,30);

Note:  After you have studied the above code: 
»Copy it onto your hard drive in Notepad or MS Word or any text editor. Save the file as "".
»Open a new text document, mention the applet parameters within the html parameters and save this file as "marquee.html".
»Compile the .java file (from DOS  prompt if you are not using a visual editor like VJ++, etc.) to check for errors and to obtain the .class file.
»Run at DOS prompt, using the command : appletviewer

Added on June 18, 2007 Comment