12/22/2011

Java applet (marquee text)



/* Java applet (marquee text) */

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class MovingBanner extends Applet implements Runnable
{

public String str=" Moving Banner ";
Thread t=null;
boolean stopflag;
public void init()
{

setBackground(Color.cyan);
setForeground(Color.blue);
}
public void start()
{
// str=getParameter("msg");
// if(str==null)
// str=" Message not found ";
// str=" " +str;
t= new Thread(this);
stopflag=false;
t.start();
}
public void stop()
{
stopflag=true;
t=null;
}
public void run()
{
char ch;
for(;;)
{
try{
repaint();
Thread.sleep(150);
ch=str.charAt(0);
str=str.substring(1,str.length());
str+=ch;
if(stopflag)
break; 
}//try
catch(InterruptedException e){}
}//for loop

}

public void paint(Graphics g)
{
Font f = new Font("Arial",Font.BOLD,25); 
g.setFont(f); 
g.drawString(str,50,30);
} 

} 
//<applet code="MovingBanner.class" height=500 width=500></applet>

No comments:

Post a Comment