Files
javalab/P14.java
Amneesh Singh 14898356a8 P6-P15: init
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
2023-06-05 03:15:38 +05:30

50 lines
1.1 KiB
Java

import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
public class P14 extends Applet implements Runnable {
private String bannerText;
private int xCoordinate;
private Thread thread;
public void init() {
bannerText = "Goofy ahh banner!";
xCoordinate = getWidth();
setBackground(Color.WHITE);
setForeground(Color.BLACK);
setFont(new Font("Arial", Font.BOLD, 20));
}
public void start() {
if (thread == null) {
thread = new Thread(this);
thread.start();
}
}
public void run() {
while (true) {
xCoordinate -= 5;
if (xCoordinate + 200 < 0) {
xCoordinate = getWidth();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
repaint();
}
}
public void paint(Graphics g) {
g.clearRect(0, 0, getWidth(), getHeight());
g.drawString(bannerText, xCoordinate, 50);
}
}