-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.java
65 lines (48 loc) · 1.53 KB
/
time.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.*;
import java.text.*;
import java.awt.*;
public class time{
public static void main(String args[]){
timeShow ts = new timeShow();
ts.showFrame();
}
}
class timeShow{
Frame f = new Frame();
Date date = new Date();
Timer timer = new Timer();
Label TimeLabel = new Label();
Label DateLabel = new Label();
SimpleDateFormat tFormat = new SimpleDateFormat("dd/MM/yyy");
SimpleDateFormat tTime = new SimpleDateFormat("hh:mm:ss");
public String time;
public String dateS;
void showFrame(){
TimerTask task = new TimerTask(){
public void run(){
Date date = new Date();
time = tTime.format(date);
dateS = tFormat.format(date);
TimeLabel.setText(time);
DateLabel.setText(dateS);
}
};
timer.scheduleAtFixedRate(task,0,1*1000);
DateLabel.setBounds(150,200,200,50);
DateLabel.setBackground(Color.yellow);
DateLabel.setForeground(Color.blue);
DateLabel.setFont(new Font("Courier New", Font.PLAIN,23));
DateLabel.setAlignment(Label.CENTER);
TimeLabel.setBackground(Color.blue);
TimeLabel.setForeground(Color.white);
TimeLabel.setBounds(150,70,200,80);
TimeLabel.setFont(new Font("Castellar", Font.PLAIN,30));
TimeLabel.setAlignment(Label.CENTER);
f.add(TimeLabel);
f.add(DateLabel);
f.setTitle("Digital Clock");
f.setSize(500,300);
f.setLayout(null);
f.setVisible(true);
}
}