-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadClock.java
More file actions
63 lines (45 loc) · 1.21 KB
/
Copy pathThreadClock.java
File metadata and controls
63 lines (45 loc) · 1.21 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
54
55
56
57
58
59
60
61
62
63
package TermProject;
import javax.swing.*;
import javax.swing.JLabel;
import java.awt.Font;
import java.util.Calendar;
public class ThreadClock extends JFrame implements Runnable{
private Thread thread;
private JLabel label;
public ThreadClock(){
super("디지털 시계");
label = new JLabel();
label.setFont(new Font("Serif",Font.PLAIN,20));
if(thread == null){
thread = new Thread(this);
thread.start();
}
add(label);
setBounds(100,100,400,100);
setVisible(true);
}
public void run(){
while(true){
Calendar cal = Calendar.getInstance();
StringBuffer now = new StringBuffer();
now.append(cal.get(Calendar.YEAR));
now.append("년 ");
now.append((cal.get(Calendar.MONTH)+1));
now.append("월 ");
now.append(cal.get(Calendar.DATE));
now.append("일 ");
now.append(cal.get(Calendar.HOUR_OF_DAY));
now.append("시 ");
now.append(cal.get(Calendar.MINUTE));
now.append("분 ");
now.append( cal.get(Calendar.SECOND));
now.append("초 ");
label.setText(now.toString());
try {
Thread.sleep(1000);
} catch(InterruptedException e) {
e.printStackTrace();
}
}
}
}