-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurTime.java
More file actions
53 lines (44 loc) · 1.18 KB
/
CurTime.java
File metadata and controls
53 lines (44 loc) · 1.18 KB
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
48
49
50
51
52
53
import java.awt.*;
import java.applet.*;
import java.util.Calendar;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
/*
<applet code="CurTime" width=300 height=50>
</applet>
*/
public class CurTime extends Applet implements Runnable {
String msg = " Java rules the Web? ";
Thread t;
boolean stopFlag;
private static final DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
public void init() {
t = null;
}
public void start() {
t = new Thread(this);
stopFlag = false;
t.start();
}
public void run() {
for( ; ; ) {
try {
repaint();
Thread.sleep(1000);
if(stopFlag)
break;
} catch(InterruptedException exc) {
}
}
}
public void stop() {
stopFlag = true;
t = null;
}
public void paint(Graphics g) {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
msg = sdf.format(cal.getTime());
g.drawString(msg, 50, 30);
}
}