-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDifficulty.java
More file actions
158 lines (122 loc) · 5.45 KB
/
Difficulty.java
File metadata and controls
158 lines (122 loc) · 5.45 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import javax.swing.JPanel;//imports
import java.awt.Color;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Difficulty extends JComponent implements MouseListener, ActionListener {//implement mouse and action listnener
private Game newGame; //Initalize game
private ImageIcon backgroundImage; //Initalize image icon
private JFrame frame;//Initalize frame
private JLabel background;//Initalize background
private ImageIcon easyImage;//Initalize image icons
private ImageIcon normalImage;
private ImageIcon hardImage;
private ImageIcon scaledEasyLarge;
private ImageIcon scaledEasy;
private ImageIcon scaledNormal;
private ImageIcon scaledNormalLarge;
private ImageIcon scaledHard;
private ImageIcon scaledHardLarge;
private JButton easy;//Initalize easy, normal hard
private JButton normal;
private JButton hard;
Difficulty() {
newGame = new Game();//Create instance of a new game
frame = new JFrame();//Create instance of a frame
background = new JLabel();//Set background
backgroundImage = new ImageIcon("Images/MainMenu.png");
background.setBounds(0, 0, 800, 400);
easy = new JButton();//Create a new instance of the play button and set bounds
easy.setBounds(280, 50, 170, 57);
easyImage = new ImageIcon("Images/Easy.png");// Set new image icon for the easy button and add action listeners
easy.addMouseListener(this);
easy.addActionListener(this);
normal = new JButton();//Create a new instance of the normal button and set bounds
normal.setBounds(280, 140, 170, 57);
normalImage = new ImageIcon("Images/Normal.png");// Set a new image icon for the normal button and add action listeners
normal.addMouseListener(this);
normal.addActionListener(this);
hard = new JButton();//Create a new instance of the hard button and set bounds
hard.setBounds(280, 230, 168, 57);
hardImage = new ImageIcon("Images/Hard.png");// Set a new image icon for the hard button and add action listeners
hard.addMouseListener(this);
hard.addActionListener(this);
Image imgBackground = backgroundImage.getImage();//Scale background
Image imgScaleBackground = imgBackground.getScaledInstance(800, 400, Image.SCALE_SMOOTH);
ImageIcon scaledBackground = new ImageIcon(imgScaleBackground);
Image imgEasy = easyImage.getImage();//Scale easy image
Image imgScaleEasy = imgEasy.getScaledInstance(200, 100, Image.SCALE_SMOOTH);
scaledEasy = new ImageIcon(imgScaleEasy);
Image imgEasyLarge = easyImage.getImage();//Scale large easy image
Image imgScaleEasyLarge = imgEasyLarge.getScaledInstance(230, 130, Image.SCALE_SMOOTH);
scaledEasyLarge = new ImageIcon(imgScaleEasyLarge);
Image imgNormal = normalImage.getImage();//Scale normal image
Image imgScaleNormal = imgNormal.getScaledInstance(200, 100, Image.SCALE_SMOOTH);
scaledNormal = new ImageIcon(imgScaleNormal);
Image imgNormalLarge = normalImage.getImage();//Scale large normal image
Image imgScaleNormalLarge = imgNormalLarge.getScaledInstance(225, 125, Image.SCALE_SMOOTH);
scaledNormalLarge = new ImageIcon(imgScaleNormalLarge);
Image imgHard = hardImage.getImage();//Scale hard image
Image imgScaleHard = imgHard.getScaledInstance(200, 100, Image.SCALE_SMOOTH);
scaledHard = new ImageIcon(imgScaleHard);
Image imgHardLarge = hardImage.getImage();//Scale large hard image
Image imgScaleHardLarge = imgHardLarge.getScaledInstance(225, 125, Image.SCALE_SMOOTH);
scaledHardLarge = new ImageIcon(imgScaleHardLarge);
background.setIcon(scaledBackground); //Set icons
easy.setIcon(scaledEasy);
normal.setIcon(scaledNormal);
hard.setIcon(scaledHard);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Add instances to frame
frame.add(easy);
frame.add(normal);
frame.add(hard);
frame.add(background);
frame.setSize(800, 400);
frame.setLayout(null);
frame.setVisible(true);
}
public void mouseEntered(MouseEvent e) {//Mouse entered
if (e.getSource() == easy) {//If mouse enters the bounds of a button, scale the image button
easy.setIcon(scaledEasyLarge);
} else if (e.getSource() == normal) {
normal.setIcon(scaledNormalLarge);
} else if (e.getSource() == hard) {
hard.setIcon(scaledHardLarge);
}
}
public void mouseExited(MouseEvent e) {//Mouse exit
if (e.getSource() == easy) {//If mouse exits the bounds of a button, reset the scale of the image
easy.setIcon(scaledEasy);
} else if (e.getSource() == normal) {
normal.setIcon(scaledNormal);
} else if (e.getSource() == hard) {
hard.setIcon(scaledHard);
}
}
public void mouseReleased(MouseEvent e) {//Abstract methods for mouse listener
}
public void mouseClicked(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void actionPerformed(ActionEvent e) {//Action performed
if (e.getSource() == easy) {//Set the difficulty and create a new window
frame.dispose();
newGame.setDifficulty("Easy");
Theme theme = new Theme(newGame);
} else if (e.getSource() == normal) {
frame.dispose();
newGame.setDifficulty("Normal");
Theme theme = new Theme(newGame);
} else if (e.getSource() == hard) {
frame.dispose();
newGame.setDifficulty("Hard");
Theme theme = new Theme(newGame);
}
}
public static void main(String[] args) {
new Main();
}
}