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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| import java.awt.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.*;
public class Main extends JFrame implements ActionListener{
private JLabel Heure;
private JButton BTN1, BTN2, BTN3;
JTextField JTF1;
private JComboBox H, MM, ss;
public Main(){
super("Horloge");
setSize(300, 300);
setLocation(0, 0);
setAlwaysOnTop(true);
setResizable(false);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
///////////////////////////////////////////////
Heure = new JLabel("HORLOGE");
Heure.setBounds(100, 0 ,120 , 35);
Heure.setFont(new Font("sansserif", Font.PLAIN, 20));
add(Heure);
javax.swing.Timer t = new javax.swing.Timer(1000, new ClockListener());
t.start();
BTN1 = new JButton("Réveil 1");
BTN1.setBounds(5, 50, 80, 25);
BTN1.addActionListener(this);
add(BTN1);
BTN2 = new JButton("Réveil 2");
BTN2.setBounds(5, 100, 80, 25);
BTN2.addActionListener(this);
add(BTN2);
JTF1 = new JTextField();
JTF1.setBounds(100, 100, 80, 25);
add(JTF1);
BTN3 = new JButton("Réveil 3");
BTN3.setBounds(5, 150, 80, 25);
BTN3.addActionListener(this);
add(BTN3);
String[] tab1 = {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
"21", "22", "23"};
H = new JComboBox(tab1);
H.setBounds(90, 150, 45, 25);
add(H);
String[] tab2 = {"00",
"01", "02", "03", "04", "05", "06", "07", "08", "09", "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"};
ss = new JComboBox(tab2);
ss.setBounds(140, 150, 45, 25);
add(ss);
String[] tab3 = {"00",
"01", "02", "03", "04", "05", "06", "07", "08", "09", "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"};
H = new JComboBox(tab3);
H.setBounds(190, 150, 45, 25);
add(H);
///////////////////////////////////////////////
setVisible(true);
}
class ClockListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
Heure.setText(" "+ df.format(Calendar.getInstance().getTime()));
}
}
public static void main(String[] args){
new Main();
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == BTN1){
UnThread thread = new UnThread();
thread.start();
}
if(e.getSource() == BTN2){
System.out.println("Aucune commande pour le moment boutton 2");
}
if(e.getSource() == BTN3){
System.out.println("Aucune commande pour le moment boutton 3");
}
}
} |