-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeacherWindow.java
299 lines (266 loc) · 12.3 KB
/
TeacherWindow.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package finalproject;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
/**
*
* @author Nasir Abbas Mangrio
*/
public class TeacherWindow extends JFrame {
private JFrame frame;
private JLabel label;
private JTextArea textField;
private JLabel optionLabel1;
private JLabel optionLabel2;
private JLabel optionLabel3;
private JLabel optionLabel4;
private JLabel correctOptionLabel;
private JTextField correctOptionTextField;
private JTextField optionTextField1;
private JTextField optionTextField2;
private JTextField optionTextField3;
private JTextField optionTextField4;
private JButton addButton;
private JButton nextButton;
private JButton finishButton;
private String question;
private String option1;
private String option2;
private String option3;
private String option4;
private String correctOption;
public static int count1 = 1;
public static int count2 = 1;
public static int count3 = 1;
private String tableCategory1;
private String tableCategory2;
private String tableCategory3;
TeacherWindow() throws SQLException, ClassNotFoundException {
super("Create Quiz");
setBounds(180, 130, 1500, 900);
getContentPane().setBackground(new Color(93, 138, 168));
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
setLayout(null);
label = new JLabel(" Question " + " :)");
label.setFont(new Font("Corbel", Font.BOLD, 20));
label.setSize(400, 70);
label.setForeground(Color.BLACK);
add(label);
textField = new JTextArea();
textField.setFont(new Font("Arial", Font.BOLD, 18));
textField.setBounds(150, 26, 730, 90);
textField.setBackground(new Color(93, 138, 168));
//textField.setEditable(false);
textField.setForeground(Color.BLACK);
textField.setBorder(javax.swing.BorderFactory.createEmptyBorder());
add(textField);
optionLabel1 = new JLabel(" Option1 :)");
optionLabel1.setFont(new Font("Corbel", Font.BOLD, 20));
optionLabel1.setSize(450, 260);
optionLabel1.setForeground(Color.BLACK);
add(optionLabel1);
optionTextField1 = new JTextField();
optionTextField1.setFont(new Font("Arial", Font.BOLD, 18));
optionTextField1.setBounds(140, 120, 730, 20);
optionTextField1.setBackground(new Color(93, 138, 168));
optionTextField1.setForeground(Color.BLACK);
optionTextField1.setBorder(javax.swing.BorderFactory.createEmptyBorder());
add(optionTextField1);
optionLabel2 = new JLabel(" Option2 :)");
optionLabel2.setFont(new Font("Corbel", Font.BOLD, 20));
optionLabel2.setSize(400, 370);
optionLabel2.setForeground(Color.BLACK);
add(optionLabel2);
optionTextField2 = new JTextField();
optionTextField2.setFont(new Font("Arial", Font.BOLD, 18));
optionTextField2.setBounds(140, 175, 730, 20);
optionTextField2.setBackground(new Color(93, 138, 168));
optionTextField2.setForeground(Color.BLACK);
optionTextField2.setBorder(javax.swing.BorderFactory.createEmptyBorder());
add(optionTextField2);
optionLabel3 = new JLabel(" Option3 :)");
optionLabel3.setFont(new Font("Corbel", Font.BOLD, 20));
optionLabel3.setSize(450, 485);
optionLabel3.setForeground(Color.BLACK);
add(optionLabel3);
optionTextField3 = new JTextField();
optionTextField3.setFont(new Font("Arial", Font.BOLD, 18));
optionTextField3.setBounds(140, 236, 730, 20);
optionTextField3.setBackground(new Color(93, 138, 168));
optionTextField3.setForeground(Color.BLACK);
optionTextField3.setBorder(javax.swing.BorderFactory.createEmptyBorder());
add(optionTextField3);
optionLabel4 = new JLabel(" Option4 :)");
optionLabel4.setFont(new Font("Corbel", Font.BOLD, 20));
optionLabel4.setSize(400, 590);
optionLabel4.setForeground(Color.BLACK);
add(optionLabel4);
optionTextField4 = new JTextField();
optionTextField4.setFont(new Font("Arial", Font.BOLD, 18));
optionTextField4.setBounds(140, 285, 730, 20);
optionTextField4.setBackground(new Color(93, 138, 168));
optionTextField4.setForeground(Color.BLACK);
optionTextField4.setBorder(javax.swing.BorderFactory.createEmptyBorder());
add(optionTextField4);
correctOptionLabel = new JLabel(" Correct option :)");
correctOptionLabel.setFont(new Font("Corbel", Font.BOLD, 20));
correctOptionLabel.setSize(400, 700);
correctOptionLabel.setForeground(Color.BLACK);
add(correctOptionLabel);
correctOptionTextField = new JTextField();
correctOptionTextField.setFont(new Font("Arial", Font.BOLD, 18));
correctOptionTextField.setBounds(190, 339, 730, 20);
correctOptionTextField.setBackground(new Color(93, 138, 168));
correctOptionTextField.setForeground(Color.BLACK);
correctOptionTextField.setBorder(javax.swing.BorderFactory.createEmptyBorder());
add(correctOptionTextField);
addButton = new JButton("Add Question");
addButton.setBounds(140, 390, 200, 60);
addButton.setFont(new Font("Corbel", Font.BOLD, 20));
addButton.setBackground(new Color(93, 138, 168));
addButton.setForeground(Color.BLACK);
addButton.setBorder(javax.swing.BorderFactory.createEmptyBorder());
add(addButton);
nextButton = new JButton("Next Question");
nextButton.setBounds(350, 390, 200, 60);
nextButton.setFont(new Font("Corbel", Font.BOLD, 20));
nextButton.setBackground(new Color(93, 138, 168));
nextButton.setForeground(Color.BLACK);
nextButton.setBorder(javax.swing.BorderFactory.createEmptyBorder());
add(nextButton);
finishButton = new JButton("Finish");
finishButton.setBounds(560, 390, 200, 60);
finishButton.setFont(new Font("Corbel", Font.BOLD, 20));
finishButton.setBackground(new Color(93, 138, 168));
finishButton.setForeground(Color.BLACK);
finishButton.setBorder(javax.swing.BorderFactory.createEmptyBorder());
add(finishButton);
nextButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
//To change body of generated methods, choose Tools | Templates.
textField.setText("");
optionTextField1.setText("");
optionTextField2.setText("");
optionTextField3.setText("");
optionTextField4.setText("");
correctOptionTextField.setText("");
}
});
finishButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
//To change body of generated methods, choose Tools | Templates.
setVisible(false);
new StatusWindow().setVisible(true);
}
});
String url = "jdbc:mysql://localhost/Teacher";
String userName = "root";
String password = "helloworld#123";
if (TopicsWindow.check.equals("Basic Java")) {
tableCategory1 = "CreateQuestions";
tableCategory2 = "CreateOptions";
tableCategory3 = "CorrectOptions";
}
if (TopicsWindow.check.equals("Intermmediate Java")) {
tableCategory1 = "CreateQuestions2";
tableCategory2 = "CreateOptions2";
tableCategory3 = "CorrectOptions2";
}
if (TopicsWindow.check.equals("Advanced Java")) {
tableCategory1 = "CreateQuestions3";
tableCategory2 = "CreateOptions3";
tableCategory3 = "CorrectOptions3";
}
/*if(SelectTopicCategory.check2.equals("Basic Java")){
tableCategory1="CreateQuestions";
tableCategory2="CreateOptions";
tableCategory3="CorrectOptions";
}
if(SelectTopicCategory.check2.equals("Intermmediate Java")){
tableCategory1="CreateQuestions2";
tableCategory2="CreateOptions2";
tableCategory3="CorrectOptions2";
}
/*if(SelectTopicCategory.check2.equals("Advanced Java")){
tableCategory1="CreateQuestions3";
tableCategory2="CreateOptions3";
tableCategory3="CorrectOptions3";
}*/
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
//To change body of generated methods, choose Tools | Templates.
if (textField.getText().equals("") || optionTextField1.getText().equals("") || optionTextField2.getText().equals("") || optionTextField3.getText().equals("") || optionTextField4.getText().equals("")) {
JOptionPane.showMessageDialog(null, " all fields are mendatory!");
}
else{
try {
question = textField.getText();
option1 = optionTextField1.getText();
option2 = optionTextField2.getText();
option3 = optionTextField3.getText();
option4 = optionTextField4.getText();
correctOption = correctOptionTextField.getText();
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection(url, userName, password);
Statement st = con.createStatement();
PreparedStatement stmt = con.prepareStatement("insert into " + tableCategory1 + " values (?,?)");
stmt.setInt(1, count1);
stmt.setString(2, question);
stmt.executeUpdate();
stmt.close();
PreparedStatement stmt2 = con.prepareStatement("insert into " + tableCategory2 + " values (?,?,?,?,?)");
stmt2.setInt(1, count2);
stmt2.setString(2, option1);
stmt2.setString(3, option2);
stmt2.setString(4, option3);
stmt2.setString(5, option4);
stmt2.executeUpdate();
stmt2.close();
PreparedStatement stmt3 = con.prepareStatement("insert into " + tableCategory3 + " values (?,?)");
stmt3.setInt(1, count3);
stmt3.setString(2, correctOption);
stmt3.executeUpdate();
stmt3.close();
con.close();
JOptionPane.showMessageDialog(null, count1 + " Question has been added");
count1++;
count2++;
count3++;
} catch (Exception e) {
}
}
}
});
setSize(1000, 500);
setVisible(true);
}
public static void main(String[] args) throws SQLException, ClassNotFoundException {
new TeacherWindow();
}
void setVisible() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}