Write a java program to scroll the text from left to right and vice versa continuously.
ScrollText.java
import java.awt.*;
import java.applet.*;
//<applet code="ScrollText" height="100" width="350"></applet>
public class ScrollText extends Applet implements Runnable
{
String banner="Hello ";
int state;
boolean stopflag;
public void init()
{
setBackground(Color.black);
setForeground(Color.green);
}
public void start()
{
Thread t=new Thread(this);
stopflag=true;
t.start();
}
public void run()
{
char ch;
try
{
while(true)
{
repaint();
Thread.sleep(150);
ch=banner.charAt(0);
banner = banner.substring(1,banner.length());
banner +=ch;
}
}
catch (InterruptedException e)
{
System.out.println(e);
}
}
public void stop()
{
stopflag=false;
Thread t=null;
}
public void paint(Graphics g)
{
Font a = new Font("Impact",Font.BOLD,45);
g.setFont(a);
g.drawString(banner,10,60);
}
}
javac ScrollText.java
appletviewer ScrollText.java
output :
0 Comments