Marquee Message Java Code


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

public class MarqueeMessage extends Applet implements Runnable
{
Thread MarqueeThread = null;
String Message = "What you want to scroll";
Font font = new Font("TimesRoman", Font.BOLD, 24);
int x, y;

public void init()
{
x = size().width;
y = size().height / 2;
}

public void start()
{
if (MarqueeThread == null)
{
MarqueeThread = new Thread(this);
MarqueeThread.start();
}
}

public void run()
{
while (true)
{
x = x - 5;
if (x == 0)
x = size().width;

repaint();
try
{
MarqueeThread.sleep(200);
}
catch (InterruptedException e)
{
}
}
}

public void paint(Graphics g)
{
g.setFont(font);
g.setColor(Color.red);
g.drawString(Message, x, y);
}
}

Return to EagleTek