Simple Banner
Excersise: 11
Display a Simple Banner Applet.
Program
import java.awt.*;
import java.applet.*;
/**/
public class Simple extends Applet implements Runnable
{
String msg="A Single Morning Banner";
Thread t=null;
int state;
boolean stopFlag;
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);
}
}
Output
Post a Comment
Thanks for your comments. Please be visit and given positive review on our site.