0% found this document useful (0 votes)
8 views

Darshjava

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Darshjava

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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

You might also like