-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockGUI.java
More file actions
30 lines (24 loc) · 825 Bytes
/
ClockGUI.java
File metadata and controls
30 lines (24 loc) · 825 Bytes
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
import javax.swing.*;
import java.awt.*;
public class ClockGUI extends JFrame {
private ClockDisplay clock = new ClockDisplay();
private JLabel label = new JLabel("", SwingConstants.CENTER);
public ClockGUI() {
setTitle("Simple Digital Clock");
setSize(400, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
label.setFont(new Font("Consolas", Font.BOLD, 48));
add(label, BorderLayout.CENTER);
Timer timer = new Timer(1000, e -> {
clock.setTimeToNow();
label.setText(clock.getTime());
});
timer.start();
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(ClockGUI::new);
}
}