-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDTimer.java
57 lines (46 loc) · 1.47 KB
/
DTimer.java
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
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class DTimer implements ActionListener {
protected JLabel viewTime; // composant permettant l'affichage du temps ecoule
protected int timeCount; // variable permettant de memoriser le temps ecoule
protected Timer timer; // objet javax.swing.Timer
// (par defaut) initialise le compteur a 0 et le delay a 1 seconde
public DTimer () {
this (60, 1000);
}
// construit un timer avec le temps et le delay donne
public DTimer (int initialTime, int delay) {
this.timeCount = initialTime;
this.viewTime = new JLabel ("Vous avez 60 secondes pour jouer un coup : " +this.timeCount);
this.timer = new Timer (delay, this);
}
// lance le compteur de temps
public void startDTimer ()
{ this.timer.start ();
}
// stop le compteur de temps
public void stopDTimer ()
{ this.timer.stop ();
}
// permet de recuperer le temps deja ecoule
public int getTime (){
return this.timeCount;
}
public void setTime(){
this.timeCount=60;
}
// permet de connaitre l'etat d'activite du timer (lance ou non)
public boolean isRunning () {
return ( this.timer.isRunning () );
}
public JLabel getViewTime(){
return this.viewTime;
}
public void actionPerformed (ActionEvent e) {
this.timeCount--;
if(this.timeCount<0) this.viewTime.setText (" Temps écoulé ! ");
else this.viewTime.setText ("Vous avez 60 secondes pour jouer un coup : " +this.timeCount);
}
}