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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| package com.perso.vue;
import java.awt.BorderLayout;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import com.perso.model.Horloge;
import com.perso.observer.Observable.Observateur;
public class Fenetre extends JFrame {
/**
*
*/
private static final long serialVersionUID = 2111676781640540652L;
private JLabel label = new JLabel();
public JLabel getLabel() {
return label;
}
public void setLabel(JLabel label) {
this.label = label;
}
private Horloge horloge;
public Fenetre() {
//initialitation de la JFrame
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setSize(200, 80);
this.setTitle("Horloge");
//on initialise l'horloge
this.horloge = new Horloge();
//on place un écouteur sur l'horloge
this.horloge.addObservateur(new Observateur() {
@Override
public void update(String hour) {
// TODO Module de remplacement de méthode auto-généré
label.setText(hour);
}
});
//on initialise le JLlabel
Font police = new Font("DS-digital", Font.TYPE1_FONT, 30);
this.label.setFont(police);
this.label.setHorizontalAlignment(JLabel.CENTER);
//on ajoute le JLABEL a la fenetre
this.getContentPane().add(this.label, BorderLayout.CENTER);
this.horloge.run();
}
public static void main(String[] args) {
// TODO Module de remplacement de méthode auto-généré
System.out.println("lancement du programme Horloge");
Fenetre fen = new Fenetre();
fen.setVisible(true);
}
} |
Partager