Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

PROGRAM

AIM : Using applet scroll a message from right to left across the applets window.
import java.awt.*;
import java.applet.*;
/*<applet code="SimpBa" width=500 height=500>
</applet>
*/
public class SimpBa extends Applet implements Runnable
{
String msg="This is a scrolling text....:)";
Thread t=null;
int state;
Font f;
boolean stopflag;
public void init()
{
f=new Font("Algerian",Font.BOLD,48);
Color t=new Color(78,65,58);
setBackground(t);
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.setFont(f);
g.drawString(msg,10,250);

showStatus("shows in status bar");


}}
OUTPUT

D:\>cd s

D:\s>javac SimpBa.java

D:\s>appletviewer SimpBa.java

You might also like