-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResltatWindowE.java
318 lines (259 loc) · 10.8 KB
/
ResltatWindowE.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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ResltatWindowE implements ActionListener {
JFrame resltatWindow = new JFrame("Quiz Game");
JMenuBar menuBar = new JMenuBar();
JMenu file = new JMenu("File");
JMenuItem howToPlay = new JMenuItem("How To Play");
JMenuItem changeColor = new JMenuItem("Change Color");
JMenuItem highScor = new JMenuItem("Highest score");
ImageIcon im = new ImageIcon(getClass().getResource("/img/logo.png"));
/*resltatPanel continer*/
JPanel remAndRusl = new JPanel();
JTextField remark =new JTextField();
JTextField highestScore =new JTextField();
JTextField numberRight =new JTextField();
JTextField percentage =new JTextField();
JButton replayButton =new JButton();
JButton ExitButton =new JButton();
public ResltatWindowE() {
resltatWindow.setSize(650, 650);
resltatWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
resltatWindow.getContentPane().setBackground(new Color(69,69,69));
resltatWindow.setResizable(false);
resltatWindow.setLayout(null);
resltatWindow.setIconImage(im.getImage());
/*adding menu bar and items */
menuBar.add(file);
file.add(changeColor);
file.add(howToPlay);
file.add(highScor);
menuBar.setBorder(BorderFactory.createEtchedBorder(1));
menuBar.setBackground(new Color(100,100,100));
file.setFont(new Font("Serif",Font.PLAIN,20));
changeColor.addActionListener(this);
howToPlay.addActionListener(this);
highScor.addActionListener(this);
/*remark and resltat panel properties */
remAndRusl.setBounds(40,40,550,360);
remAndRusl.setBackground(new Color(40,40,40));
remAndRusl.setLayout(null);
/*remark properties */
remAndRusl.add(remark);
remark.setBounds(0, 0, 550, 90);
remark.setText(getRemark());
remark.setBorder(BorderFactory.createEtchedBorder(1));
remark.setBackground(Methods.backgroundColor);
remark.setForeground(Methods.foregroundColor);
remark.setFont(new Font("Serif",Font.BOLD,30));
remark.setHorizontalAlignment(JTextField.CENTER);
remark.setEditable(false);
/* highest Score properties */
remAndRusl.add(highestScore);
highestScore.setBounds(0, 90,550,90);
highestScore.setText(" Best Score " + Methods.readBestScorefromTheFile() +" % " );
highestScore.setBorder(BorderFactory.createEtchedBorder(1));
highestScore.setBackground(Methods.backgroundColor);
highestScore.setForeground(Methods.foregroundColor);
highestScore.setFont(new Font("Serif",Font.BOLD,30));
highestScore.setHorizontalAlignment(JTextField.LEFT);
highestScore.setEditable(false);
/*number right properties */
remAndRusl.add(numberRight);
numberRight.setBounds(0, 180, 550, 90);
numberRight.setText(" Right answers " + QuestionWindowE.numberRight() );
numberRight.setBorder(BorderFactory.createEtchedBorder(1));
numberRight.setBackground(Methods.backgroundColor);
numberRight.setForeground(Methods.foregroundColor);
numberRight.setFont(new Font("Serif",Font.BOLD,30));
numberRight.setHorizontalAlignment(JTextField.LEFT);
numberRight.setEditable(false);
/*percentage properties */
remAndRusl.add(percentage);
percentage.setBounds(0, 270, 550, 90);
percentage.setText( " Percentage "+ QuestionWindowE.results() +" % " );
percentage.setBorder(BorderFactory.createEtchedBorder(1));
percentage.setBackground(Methods.backgroundColor);
percentage.setForeground(Methods.foregroundColor);
percentage.setFont(new Font("Serif",Font.BOLD,30));
percentage.setHorizontalAlignment(JTextField.LEFT);
percentage.setEditable(false);
highestScore.setBackground(Methods.borderColor);
remark.setBackground(Methods.borderColor);
numberRight.setBackground(Methods.borderColor);
percentage.setBackground(Methods.borderColor);
replayButton.setBackground(Methods.borderColor);
/*replay Button properties */
replayButton.setBounds(350 ,435, 200 , 70);
replayButton.setFont(new Font("Serif",Font.BOLD,30));
replayButton.setFocusable(false);
replayButton.addActionListener(this);
replayButton.setText("Replay");
replayButton.setBackground(new Color(40,40,40));
replayButton.setForeground(Methods.foregroundColor);
replayButton.setBorder(BorderFactory.createLineBorder(Methods.borderColor,3,true));
replayButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
replayButton.setBackground(Methods.borderColor);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
replayButton.setBackground(new Color(40,40,40));
}
});
/*Exit Button properties */
ExitButton.setBounds(80,435 , 200 ,70);
ExitButton.setFont(new Font("Serif",Font.BOLD,30));
ExitButton.setFocusable(false);
ExitButton.addActionListener(this);
ExitButton.setText("Exit");
ExitButton.setBackground(new Color(40,40,40));
ExitButton.setForeground(Methods.foregroundColor);
ExitButton.setBorder(BorderFactory.createLineBorder(Methods.borderColor,3,true));
ExitButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
ExitButton.setBackground(Methods.borderColor);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
ExitButton.setBackground(new Color(40,40,40));
}
});
/* Adding resltatWindow */
resltatWindow.add(remAndRusl);
resltatWindow.add(replayButton);
resltatWindow.add(ExitButton);
resltatWindow.setJMenuBar(menuBar);
resltatWindow.setVisible(true);
resltatWindow.setLocation(350, 40);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == ExitButton ) {
Methods.writeBestScoreInTheFile();
System.exit(0);
}
if(e.getSource() == replayButton){
Methods.writeBestScoreInTheFile();
QuestionFieldsWindowE.InSelected();
new WelcomeWindow();
resltatWindow.setVisible(false);
}
if(e.getSource() == howToPlay){
JDialog H_P = new JDialog(resltatWindow , "How To Play");
JTextArea howToPlay_text =new JTextArea();
JButton b = new JButton("Ok");
H_P.setIconImage(im.getImage());
H_P.setLocationRelativeTo(resltatWindow);
H_P.setLayout(null);
H_P.setSize(800,500);
H_P.setModal(false);
H_P.setLocation(280,100);
H_P.add(b);
H_P.add(howToPlay_text);
H_P.setVisible(true);
H_P.getContentPane().setBackground(Methods.backgroundColor);
H_P.setResizable(false);
H_P.setLayout(null);
howToPlay_text.setBounds(18,20,750,360);
howToPlay_text.setLineWrap(true);
howToPlay_text.setWrapStyleWord(true);
howToPlay_text.setBackground(Methods.backgroundColor);
howToPlay_text.setForeground(Methods.foregroundColor);
howToPlay_text.setFont(new Font("Serif",Font.BOLD,22));
howToPlay_text.setEditable(false);
howToPlay_text.setText("Welcome to the most educational and fun games, where you can educate yourself in a fun and interesting way, and in your own way, you can choose your own world that you belong to you can choose your favorite colore, and make it to correct the background of the game , aslo you may choose others fields categories such as Historical, religoins, or scientific, To make the game more competitive and intresting, you can definer your playing level. \nThis game is shorted in some of the rulese : \n- To have three levels ( Easy, Medium and Hard ), which are measured by the response time for each question for each level ** Easy 12 seconds ** Medium 10 seconds ** Hard 8 seconds\nIn each field there are 10 questions and in each question there are three suggestions of which only one is correct.");
b.setBounds(340, 400, 80, 40);
b.setFont(new Font("Serif",Font.BOLD,25));
b.setFocusable(false);
b.setBackground(new Color(40,40,40));
b.setForeground(Methods.foregroundColor);
b.setBorder(BorderFactory.createLineBorder(Methods.borderColor,2,true));
b.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
b.setBackground(Methods.borderColor);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
b.setBackground(new Color(40,40,40));
}
});
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
H_P.setVisible(false);
}
});
}
if(e.getSource() == changeColor){
Color c = JColorChooser.showDialog(null,"Color Chooser", Methods.borderColor);
if (c !=null ){
Methods.ChangeColor(c);
highestScore.setBackground(Methods.borderColor);
remark.setBackground(Methods.borderColor);
numberRight.setBackground(Methods.borderColor);
percentage.setBackground(Methods.borderColor);
replayButton.setBackground(Methods.borderColor);
replayButton.setBorder(BorderFactory.createLineBorder(Methods.borderColor,3,true));
ExitButton.setBackground(Methods.borderColor);
ExitButton.setBorder(BorderFactory.createLineBorder(Methods.borderColor,3,true));
}
}
if(e.getSource() == highScor){
JDialog H_S = new JDialog(resltatWindow,"Best Score");
final JLabel l = new JLabel("Best Score" + (Methods.readBestScorefromTheFile()) + " %");
JButton b = new JButton("Ok");
H_S.setIconImage(im.getImage());
H_S.setLocationRelativeTo(resltatWindow);
H_S.setLayout(null);
H_S.setSize(340, 170);
H_S.setModal(false);
H_S.setLocation(500,300);
H_S.add(l);
H_S.add(b);
H_S.setVisible(true);
H_S.getContentPane().setBackground(Methods.backgroundColor);
H_S.setResizable(false);
H_S.setLayout(null);
b.setBounds(120, 70, 80, 40);
b.setFont(new Font("Serif",Font.BOLD,25));
b.setFocusable(false);
b.setBackground(new Color(40,40,40));
b.setForeground(Methods.foregroundColor);
b.setBorder(BorderFactory.createLineBorder(Methods.borderColor,2,true));
b.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
b.setBackground(Methods.borderColor);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
b.setBackground(new Color(40,40,40));
}
});
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
H_S.setVisible(false);
}
});
l.setBounds(10,10,310,50);
l.setBorder(BorderFactory.createEtchedBorder(1));
l.setBackground(Methods.backgroundColor);
l.setForeground(Methods.foregroundColor);
l.setFont(new Font("Serif",Font.BOLD,24));
l.setHorizontalAlignment(JTextField.CENTER);
}
}
/*method return Remark */
String getRemark(){
String r = "" ;
if(QuestionWindow.results() <= 20)
r = "You can do better";
if(20 < QuestionWindow.results() && QuestionWindow.results() <= 40)
r = "Keep learning";
if(40 < QuestionWindow.results() && QuestionWindow.results() <= 60)
r = "Well done,but you lack a little focus";
if(60 < QuestionWindow.results() && QuestionWindow.results() <= 80)
r = "You have good skills";
if(80 < QuestionWindow.results())
r = "Great standard and excellent job";
return r;
}
}