-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleBanner.java
47 lines (45 loc) · 1.11 KB
/
SimpleBanner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.awt.*;
import java.applet.*;
/*
<applet code="SimpleBanner" width=300 height=50>
</applet>
*/
public class SimpleBanner extends Applet implements Runnable {
String msg = " A Simple Moving Banner.";
Thread t = null;
int state;
boolean stopFlag;
// Set colors and initialize thread.
public void init() {
setBackground(Color.cyan);
setForeground(Color.red);
}
public void start() {
t = new Thread(this);
stopFlag = false;
t.start();
}
public void run() {
char ch;
// Display banner
for (;;) {
try {
repaint();
Thread.sleep(250);
ch = msg.charAt(0);
msg = msg.substring(1, msg.length());
msg += ch;
if (stopFlag)
break;
} catch (InterruptedException e) {
}
}
}
public void stop() {
stopFlag = true;
t = null;
}
public void paint(Graphics g) {
g.drawString(msg, 50, 30);
}
}