Add clock application

This commit is contained in:
Thibaud Gasser 2018-09-29 17:32:11 +02:00
parent 11fe2bc31d
commit 12dfbbc705
3 changed files with 62 additions and 0 deletions

15
clock/pom.xml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>swingapps</artifactId>
<groupId>fr.uha.gasser</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>clock</artifactId>
</project>

View File

@ -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 linterface est confié au DTE
EventQueue.invokeLater(Clock::new);
}
}

View File

@ -22,5 +22,8 @@
</plugin>
</plugins>
</build>
<modules>
<module>clock</module>
</modules>
</project>