From 12dfbbc7057bc78e4cc8c221eb5169e84fde4188 Mon Sep 17 00:00:00 2001 From: Thibaud Date: Sat, 29 Sep 2018 17:32:11 +0200 Subject: [PATCH] Add clock application --- clock/pom.xml | 15 +++++++ .../main/java/fr/uha/gasser/clock/Clock.java | 44 +++++++++++++++++++ pom.xml | 3 ++ 3 files changed, 62 insertions(+) create mode 100644 clock/pom.xml create mode 100644 clock/src/main/java/fr/uha/gasser/clock/Clock.java diff --git a/clock/pom.xml b/clock/pom.xml new file mode 100644 index 0000000..1c882a0 --- /dev/null +++ b/clock/pom.xml @@ -0,0 +1,15 @@ + + + + swingapps + fr.uha.gasser + 1.0-SNAPSHOT + + 4.0.0 + + clock + + + \ No newline at end of file diff --git a/clock/src/main/java/fr/uha/gasser/clock/Clock.java b/clock/src/main/java/fr/uha/gasser/clock/Clock.java new file mode 100644 index 0000000..b638a53 --- /dev/null +++ b/clock/src/main/java/fr/uha/gasser/clock/Clock.java @@ -0,0 +1,44 @@ +package fr.uha.gasser.clock; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.text.DateFormat; +import java.util.Date; + +public class Clock extends JFrame { + + private final JTextField timeField; + + private Clock() { + super("Clock example"); + + setDefaultCloseOperation(EXIT_ON_CLOSE); + timeField = new JTextField(); + timeField.setColumns(10); + timeField.setEditable(false); + + getContentPane().add(timeField); + + ActionListener timerTask = new ActionListener() { + private DateFormat df = DateFormat.getTimeInstance(DateFormat.MEDIUM); + + @Override + public void actionPerformed(ActionEvent actionEvent) { + timeField.setText(df.format(new Date())); + } + }; + + pack(); + setVisible(true); + + Timer timer = new Timer(500, timerTask); + timer.start(); + } + + public static void main(String[] args) { + // La création de l’interface est confié au DTE + EventQueue.invokeLater(Clock::new); + } +} diff --git a/pom.xml b/pom.xml index b3cb84f..e8eb020 100644 --- a/pom.xml +++ b/pom.xml @@ -22,5 +22,8 @@ + + clock + \ No newline at end of file