-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenuPrincipal.java
More file actions
104 lines (90 loc) · 3.83 KB
/
Copy pathMenuPrincipal.java
File metadata and controls
104 lines (90 loc) · 3.83 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
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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MenuPrincipal extends PainelComImagem {
public MenuPrincipal(CardLayout layout, JPanel painelPrincipal) {
super("imagens/metro.jpg");
setLayout(null);
setOpaque(false);
JButton btnJogar = criarBotao("Jogar");
JButton btnOpcoes = criarBotao("Opções");
JButton btnPlacar = criarBotao("Placar");
JButton btnSair = criarBotao("Sair");
btnJogar.setBounds(430, 200, 400, 60);
btnOpcoes.setBounds(430, 280, 400, 60);
btnPlacar.setBounds(430, 360, 400, 60);
btnSair.setBounds(430, 440, 400, 60);
btnJogar.addActionListener(e -> {
Inventario.limpar();
layout.show(painelPrincipal, "Login");
SomUtils.tocarSom("/sons/click.wav");
});
btnOpcoes.addActionListener(e -> {
SomUtils.tocarSom("/sons/click.wav");
});
btnPlacar.addActionListener(e -> {
SomUtils.tocarSom("/sons/click.wav");
});
btnSair.addActionListener(e -> {
SomUtils.tocarSom("/sons/click.wav");
});
btnOpcoes.addActionListener(e -> layout.show(painelPrincipal, "Opções"));
btnPlacar.addActionListener(e -> layout.show(painelPrincipal, "Placar"));
btnSair.addActionListener(e -> System.exit(0));
add(btnJogar);
add(btnOpcoes);
add(btnPlacar);
add(btnSair);
//adiciona animacoes
adicionarAnimacoesBotoes(new JButton[] { btnJogar, btnOpcoes, btnPlacar, btnSair });
}
private JButton criarBotao(String texto) {
JButton botao = new JButton(texto);
botao.setFont(new Font("Arial", Font.BOLD, 30));
botao.setBackground(new Color(255, 255, 255, 128)); // Cor azul com transparência
botao.setForeground(Color.WHITE); // Cor do texto
botao.setFocusPainted(false);
botao.setContentAreaFilled(true); // Permite que a cor de fundo seja exibida
botao.setBorder(new RoundedBorder(20)); // Borda arredondada
return botao;
}
private void adicionarAnimacoesBotoes(JButton[] botoes) {
Color buttonBackground = new Color(10, 30, 80, 200);
// cor ao passar o mouse
Color buttonHoverBackground = new Color(5, 15, 40, 255);
MouseAdapter mouseAdapter = new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
JButton button = (JButton) e.getSource();
button.setBackground(buttonHoverBackground);
button.setBounds(button.getX() - 5, button.getY() - 5, button.getWidth() + 10, button.getHeight() + 10);
button.revalidate();
button.repaint();
}
@Override
public void mouseExited(MouseEvent e) {
JButton button = (JButton) e.getSource();
button.setBackground(buttonBackground);
button.setBounds(button.getX() + 5, button.getY() + 5, button.getWidth() - 10, button.getHeight() - 10);
button.revalidate();
button.repaint();
}
};
for (JButton botao : botoes) {
botao.setBackground(buttonBackground);
botao.setForeground(Color.WHITE);
botao.setFocusPainted(false);
botao.setContentAreaFilled(true);
botao.setBorder(new RoundedBorder(20));
botao.addMouseListener(mouseAdapter);
}
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(new Color(0, 0, 0, 0));
g2d.fillRect(0, 0, getWidth(), getHeight());
}
}