-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomePage.java
More file actions
executable file
·182 lines (141 loc) · 5.06 KB
/
Copy pathHomePage.java
File metadata and controls
executable file
·182 lines (141 loc) · 5.06 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class HomePage {
private JFrame frame;
private JLabel lblUserName;
private JLabel lblLevel;
private JLabel lblXP;
private JComboBox comboBoxGameMode;
private JComboBox comboBoxCategory;
private JComboBox comboBoxDifficultLevel;
private JButton btnPlay;
// Variables that hold difficult level and word category
public static String difficultLevel;
public static String categoryName;
/**
* Launch the application.
* @wbp.parser.entryPoint
*/
public static void Home() {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
HomePage window = new HomePage();
window.initialize();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 708, 605);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JLabel lblNewLabel = new JLabel("Guessing game ");
lblNewLabel.setFont(new Font("Algerian", Font.PLAIN, 30));
lblNewLabel.setBounds(286, 13, 300, 66);
frame.getContentPane().add(lblNewLabel);
lblUserName = new JLabel("User Name here");
lblUserName.setBounds(12, 61, 254, 16);
frame.getContentPane().add(lblUserName);
lblLevel = new JLabel("Their current level");
lblLevel.setBounds(12, 90, 254, 16);
frame.getContentPane().add(lblLevel);
lblXP = new JLabel("Their current Xp");
lblXP.setBounds(12, 119, 254, 16);
frame.getContentPane().add(lblXP);
comboBoxGameMode = new JComboBox();
comboBoxGameMode.setBounds(322, 197, 168, 38);
frame.getContentPane().add(comboBoxGameMode);
JLabel lblNewLabel_1 = new JLabel("Game Mode");
lblNewLabel_1.setBounds(167, 197, 99, 38);
frame.getContentPane().add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("Difficulty Level");
lblNewLabel_2.setBounds(167, 352, 99, 38);
frame.getContentPane().add(lblNewLabel_2);
comboBoxDifficultLevel = new JComboBox();
comboBoxDifficultLevel.setBounds(322, 352, 168, 38);
frame.getContentPane().add(comboBoxDifficultLevel);
btnPlay = new JButton("Let's Play");
btnPlay.setBounds(193, 467, 97, 25);
frame.getContentPane().add(btnPlay);
JButton btnLogOff = new JButton("Log off");
btnLogOff.setBounds(381, 467, 97, 25);
frame.getContentPane().add(btnLogOff);
comboBoxCategory = new JComboBox();
comboBoxCategory.setBounds(322, 267, 168, 38);
frame.getContentPane().add(comboBoxCategory);
JLabel lblWordCategory = new JLabel("Word Category");
lblWordCategory.setBounds(167, 267, 99, 38);
frame.getContentPane().add(lblWordCategory);
// Play button event handler
btnPlay.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String gameMode = comboBoxGameMode.getSelectedItem().toString();
difficultLevel = comboBoxDifficultLevel.getSelectedItem().toString();
categoryName = comboBoxCategory.getSelectedItem().toString();
// Let user pick game mode
if(gameMode.equals("Drawing")) {
DrawingPage draw = new DrawingPage(difficultLevel);
draw.main(new String[] {"sthg"});
frame.dispose();
}
else {
GuessingPage guess = new GuessingPage();
guess.main(new String[] {"sthg"});
frame.dispose();
}
}
});
// Log off button
btnLogOff.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
LoginPage login = new LoginPage();
login.run();
frame.dispose();
}
});
InitializeComboBox();
DisplayUsersInformation();
}
private void InitializeComboBox() {
String[] difficultMode= Client.getNeededInfor("DIFFICULT_LEVEL");
// Get combobox selection to determine time period
String[] timePeriod = Client.getNeededInfor("TIME_PERIOD", "Hard");
// Get word category name
String[] wordCategory = Client.getNeededInfor("WORD_CATEGORY");
// Combo box for game mode
comboBoxGameMode.addItem("Drawing");
comboBoxGameMode.addItem("Guessing");
// Combo box for difficult level
for ( int i = 1 ; i < difficultMode.length; i++) {
comboBoxDifficultLevel.addItem(difficultMode[i]);
}
for( int i = 1; i < wordCategory.length ; i++) {
comboBoxCategory.addItem(wordCategory[i]);
}
}
private void DisplayUsersInformation() {
// Variables that will hold user's username, level and xp
String[] userInfor = Client.getNeededInfor("USER_INFO");
// Display user's information
lblUserName.setText("Name: " +userInfor[2]);
lblLevel.setText("Current level: "+userInfor[3]);
lblXP.setText("Current Xp: "+userInfor[4]);
}
}