forked from lucasmartiniano6/mc322-projeto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRelogio.java
More file actions
80 lines (64 loc) · 1.91 KB
/
Copy pathRelogio.java
File metadata and controls
80 lines (64 loc) · 1.91 KB
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
import javax.swing.*;
import java.awt.event.*;
public class Relogio {
private String corDono;
private boolean iniciado;
private JLabel label;
private int minutos;
private int segundos;
private Timer timer;
public Relogio(int tempo, String corDono){
this.segundos = 0;
this.corDono =corDono;
this.minutos = tempo;
this.iniciado = false;
setLabelRelogio();
}
public boolean isStarted(){
return iniciado;
}
public String getCorDono() {
return corDono;
}
public Timer getTimer(){
return timer;
}
// cria uma janela para o relogio
public void setLabelRelogio(){
this.label = new JLabel(minutos + ":" + segundos);
label.setHorizontalAlignment(JLabel.CENTER);
label.setVerticalAlignment(JLabel.CENTER);
label.repaint();
}
public JLabel getLabelRelogio(){
return label;
}
public void startRelogio(){
iniciado = true;
this.timer = new Timer(1000, new ActionListener(){
public void actionPerformed(ActionEvent e){
if (segundos !=0){
segundos--;
} else if(segundos == 0){
segundos = 59;
minutos--;
}
if (minutos == 0 && segundos == 0){
timer.stop();
if(getCorDono().equals("branca"))
Tabuleiro.endGame("O tempo do jogador acabou", "preta");
else
Tabuleiro.endGame("O tempo do jogador acabou", "branca");
}
label.setText(minutos + ":" + segundos);
}
});
timer.start();
}
public void pausaRelogio(Timer timer){
timer.stop();
}
public void despausaRelogio(Timer timer){
timer.start();
}
}