Add clock application
This commit is contained in:
parent
11fe2bc31d
commit
12dfbbc705
15
clock/pom.xml
Normal file
15
clock/pom.xml
Normal 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>
|
44
clock/src/main/java/fr/uha/gasser/clock/Clock.java
Normal file
44
clock/src/main/java/fr/uha/gasser/clock/Clock.java
Normal 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 l’interface est confié au DTE
|
||||||
|
EventQueue.invokeLater(Clock::new);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user