-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockFrame.java
More file actions
93 lines (76 loc) · 2.61 KB
/
ClockFrame.java
File metadata and controls
93 lines (76 loc) · 2.61 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package DigitalClock;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;
public class ClockFrame extends JFrame{
private static final long serialVersionUID = 1L;
private JLabel clocklbl, datelbl, daylbl;
private SimpleDateFormat timeFormat, dayFormat, dateFormat;
private String time, day, datetxt;
public ClockFrame() {
initialized();
}
private void initialized() {
Border border = BorderFactory.createLineBorder(Color.green, 1);
this.setTitle("Digital Clock");
this.setSize(new Dimension(300, 180));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setLayout(null);
clocklbl = new JLabel();
clocklbl.setFont(new Font("Orbitron", Font.PLAIN, 24));
clocklbl.setForeground(Color.green);
clocklbl.setBackground(Color.black);
clocklbl.setOpaque(true);
clocklbl.setLocation(new Point(0, 0));
clocklbl.setSize(new Dimension(300, 30));
clocklbl.setHorizontalAlignment(JLabel.CENTER);
daylbl = new JLabel();
daylbl.setFont(new Font("Orbitron", Font.PLAIN, 26));
daylbl.setSize(new Dimension(300, 30));
daylbl.setLocation(new Point(0, 50));
daylbl.setHorizontalAlignment(JLabel.CENTER);
daylbl.setForeground(Color.black);
//daylbl.setBorder(border);
datelbl = new JLabel();
datelbl.setFont(new Font("Verdana", Font.ITALIC, 20));
datelbl.setForeground(Color.black);
datelbl.setSize(new Dimension(300, 30));
datelbl.setLocation(new Point(0, 100));
datelbl.setHorizontalAlignment(JLabel.CENTER);
datelbl.setOpaque(true);
datelbl.setBackground(Color.decode("#ffff4d"));
//datelbl.setBorder(border);
this.add(clocklbl);
this.add(daylbl);
this.add(datelbl);
this.setVisible(true);
this.setLocationRelativeTo(null);
tickClock();
}
private void tickClock() {
while(true) {
timeFormat = new SimpleDateFormat("hh:mm:ss a");
time = timeFormat.format(Calendar.getInstance().getTime());
clocklbl.setText(time);
dayFormat = new SimpleDateFormat("EEEE");
day = dayFormat.format(Calendar.getInstance().getTime());
daylbl.setText(day);
dateFormat = new SimpleDateFormat("MMMM dd, yyyy");
datetxt = dateFormat.format(Calendar.getInstance().getTime());
datelbl.setText(datetxt);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}