-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUhrGUI.java
More file actions
35 lines (26 loc) · 877 Bytes
/
Copy pathUhrGUI.java
File metadata and controls
35 lines (26 loc) · 877 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
31
32
33
34
35
import javax.swing.*; //swing
import java.awt.*;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public class UhrGUI extends JFrame { //JFrame
private JLabel uhrLabel;
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
public UhrGUI() {
setTitle("Digitale Uhr");
setSize(200, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
uhrLabel = new JLabel(); //
uhrLabel.setFont(new Font("Monospaced", Font.BOLD, 24));
add(uhrLabel);
Timer timer = new Timer(1000, e -> {
LocalTime jetzt = LocalTime.now();
uhrLabel.setText(jetzt.format(formatter));
});
timer.start();
setVisible(true);
}
public static void main(String[] args) {
new UhrGUI();
}
}