Simport java.awt.
*;
import java.applet.*;
public class MovingBanner extends Applet implements Runnable {
private String message = "Moving Banner";
private int xCoordinate = 0;
private int yCoordinate = 20;
private Thread t = null;
private boolean stopFlag;
public void init() {
setBackground(Color.black);
setForeground(Color.green);
}
public void start() {
t = new Thread(this);
stopFlag = false;
t.start();
}
public void run() {
while (!stopFlag) {
try {
Thread.sleep(250); // Adjust speed here (in milliseconds)
repaint();
xCoordinate += 10; // Adjust movement here
if (xCoordinate > getWidth()) {
xCoordinate = 0 - message.length() * 10; // Reset x-coordinate
to start
}
} catch (InterruptedException e) {
System.out.println("Thread interrupted: " + e.getMessage());
}
}
}
public void stop() {
stopFlag = true;
t = null;
}
public void paint(Graphics g) {
g.drawString(message, xCoordinate, yCoordinate);
}
}S