-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHomePanel.java
85 lines (68 loc) · 2.35 KB
/
HomePanel.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
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
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.*;
public class HomePanel extends JPanel {
Image bgImage;
JButton startButton;
JButton exitButton;
HomePanel() {
setBounds(0, 0, 560, 680);
setLayout(null);
loadImages();
loadButtons();
startGame();
exitGame();
}
void loadImages() {
try {
BufferedImage bufferBgImg = ImageIO.read(HomePanel.class.getResource("./Images/Logo.png"));
bgImage = bufferBgImg.getScaledInstance(560, 680, Image.SCALE_DEFAULT);
} catch (Exception e) {
System.out.println("Image can't find");
}
}
void startGame() {
startButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new GameFrame();
}
});
}
void loadButtons() {
startButton = new JButton("START");
startButton.setFont(
new Font("Agency FB", Font.BOLD, 32));
startButton.setBackground(Color.GREEN);
startButton.setBounds(150, 540, 100, 50);
exitButton = new JButton("EXIT");
exitButton.setFont(
new Font("Agency FB", Font.BOLD, 32));
exitButton.setBackground(Color.RED);
exitButton.setBounds(300, 540, 100, 50);
add(startButton);
add(exitButton);
}
void exitGame() {
exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int a = JOptionPane.showConfirmDialog(null, "Are you sure?", "EXIT", JOptionPane.YES_NO_CANCEL_OPTION);
if (a == JOptionPane.YES_OPTION) {
System.exit(0);
}
// JPanel panel = new QuestionOnExitPanel();
// JOptionPane.showMessageDialog(null,panel,"EXIT",JOptionPane.PLAIN_MESSAGE);
}
});
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(bgImage, 0, 0, null);
}
}