P6-P15: init

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2023-06-05 03:15:38 +05:30
parent 539adc94da
commit 14898356a8
16 changed files with 675 additions and 0 deletions

49
P14.java Normal file
View File

@@ -0,0 +1,49 @@
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);
}
}