-
Notifications
You must be signed in to change notification settings - Fork 0
/
Final.java
58 lines (50 loc) · 1.85 KB
/
Final.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
58
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class Final extends JPanel {
private Font Fonte;
private boolean resultado = Player.resultado;
public Final() {
Fonte = DefinirFonte.fonte();
setLayout(new BorderLayout());
JPanel background = new JPanel(new GridBagLayout());
background.setFocusable(true);
background.setBackground(Color.BLACK);
background.setOpaque(true);
JLabel gameOverLabel = resultado ? congratulationsMsg() : finalMsg();
gameOverLabel.setForeground(Color.RED);
background.add(gameOverLabel);
add(background, BorderLayout.CENTER);
Timer colorChangeTimer = new Timer(500, new ActionListener() {
private boolean colorFlag = false;
@Override
public void actionPerformed(ActionEvent e) {
if (colorFlag) {
gameOverLabel.setForeground(Color.RED);
} else {
gameOverLabel.setForeground(Color.YELLOW);
}
colorFlag = !colorFlag;
}
});
colorChangeTimer.start();
Timer exitTimer = new Timer(7000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
exitTimer.setRepeats(false); // Isso garante que o timer só será acionado uma vez
exitTimer.start();
}
private JLabel finalMsg() {
JLabel finalMsg = new JLabel("GAME OVER");
finalMsg.setFont(Fonte.deriveFont(Font.PLAIN,90f));
return finalMsg;
}
private JLabel congratulationsMsg() {
JLabel congratulationsMsg = new JLabel("CONGRATULATIONS");
congratulationsMsg.setFont(Fonte.deriveFont(Font.PLAIN,90f));
return congratulationsMsg;
}
}