The marquee applet


A classic example of visual effects used on the web.


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


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


public void init(){
setBackground(Color.red);
setForeground(Color.white);
}

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

for( ; ; ) {
try {
repaint();
Thread.sleep(250);
ch = msg.charAt(0);
msg = msg.substring(1, msg.length());
msg +=ch;
if(stopFlag)
break;
} 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 "marquee.java".

»  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 marquee.java



Added on July 8, 2007 Comment
}