1 import java.awt.*;
2 import java.awt.event.*;
3 import java.time.*;
4 import javax.swing.*;
5 import javax.swing.Timer;
6
7 /**
8
9 */
10 public class TimerTester
11 {
12 public static void main(String[] args)
13 {
14 JFrame frame = new JFrame();
15
16 final int FIELD_WIDTH = 20;
17 JTextField textField = new JTextField(FIELD_WIDTH);
18
19 frame.setLayout(new FlowLayout());
20 frame.add(textField);
21
22 ActionListener listener
23 = event -> textField.setText(Instant.now().toString());
24 final int DELAY = 1000;
25 //
26 Timer t = new Timer(DELAY, listener);
27 t.start();
28
29 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
30 frame.pack();
31 frame.setVisible(true);
32 }
33 }