/Volumes/GoogleDrive/My Drive/IB CS Resources/Final CS IA/20058_Computer_Science_IA/src/coreGUI/TestingSessionPanel.java |
1 package coreGUI;
2
3 import java.awt.event.WindowEvent;
4 import java.io.BufferedReader;
5 import java.io.FileReader;
6 import java.io.IOException;
7 import javax.swing.DefaultCellEditor;
8 import javax.swing.JComboBox;
9 import javax.swing.table.TableColumn;
10
11 /*
12 * To change this license header, choose License Headers in Project Properties.
13 * To change this template file, choose Tools | Templates
14 * and open the template in the editor.
15 */
16
17 /**
18 *
19 * @author 20058
20 */
21 public class TestingSessionPanel extends javax.swing.JFrame {
22 private SetOfQs userSetOfQs = new SetOfQs();
23 private String[] arrSolution;
24 int correctAnswer=0;
25 int wrongAnswer=0;
26 int emptyAnswer = 0;
27
28
29 /**
30 * Creates new form testingSession
31 */
32 public TestingSessionPanel() {
33 initComponents();
34
35
36 }
37
38
39 //TestPanel's Methods
40 private void loadSetOfQsAnswer(String name){
41 try{
42 FileReader fr = new FileReader(name+".txt");
43 BufferedReader br = new BufferedReader(fr);
44 String line=br.readLine();
45
46
47 arrSolution = line.split(";");
48
49
50 }catch(IOException ex){
51
52 }
53 }
54 private void createTestComboBox() {
55 int testTableNumbQs = userSetOfQs.getNumberOfQ();
56 for (int row = 0;row<testTableNumbQs;row++){
57 testTable.setValueAt(row+1, row, 0);
58 testTable.setValueAt("Empty", row, 1);
59
60
61 }
62 String[] allChoices = new String[]{"Empty","A.","B.","C.","D.","E.","F."};
63 int nchs = (Integer)userSetOfQs.getNumberOfChoices();
64 nchs++;
65 String[] choices = new String[nchs];
66 for(int i =0;i<nchs;i++){
67 choices[i] = allChoices[i];
68 }
69 JComboBox<String> choiceList = new JComboBox<>(choices);
70 TableColumn c1 = testTable.getColumnModel().getColumn(1);
71 c1.setCellEditor(new DefaultCellEditor(choiceList));
72
73 }
74 public TestingSessionPanel(SetOfQs obtainedSetOfQs) {
75 initComponents();
76 userSetOfQs = obtainedSetOfQs;
77 createTestComboBox();
78 nameLabel.setText(userSetOfQs.getSetOfQsName());
79 loadSetOfQsAnswer(userSetOfQs.getSetOfQsName());
80 descriptionLabel.setText(userSetOfQs.getNotes());
81 }
82
83 //This is imported
84 private void systemExit(){
85 WindowEvent windowCloses = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
86 windowCloses.getWindow().hide();
87 }
88
89
361
362 private void getResultButtonActionPerformed(java.awt.event.ActionEvent evt) {
363 // TODO add your handling code here:
364
365 }
366
367 private void dismissButtonActionPerformed(java.awt.event.ActionEvent evt) {
368 // TODO add your handling code here:
369 //System.exit(0);
370
371 }
372
373 private void dismissButtonMouseReleased(java.awt.event.MouseEvent evt) {
374 // TODO add your handling code here:
375 systemExit();
376 }
377
378 private void getResultButtonMouseReleased(java.awt.event.MouseEvent evt) {
379 // TODO add your handling code here:
380 for(int i = 0;i<userSetOfQs.getNumberOfQ(); i++ ){
381 if(arrSolution[i].equals(testTable.getValueAt(i, 1))){
382 correctAnswer++;
383 } else {
384 if((testTable.getValueAt(i, 1).equals("Empty"))){
385 emptyAnswer++;
386 } else{
387 wrongAnswer++;
388 }
389 }
390 testTable.setValueAt(arrSolution[i], i, 2);
391 }
392 double fullScoreDoub = userSetOfQs.getInitialScore() + (userSetOfQs.getNumberOfQ() * userSetOfQs.getCorrectAnswerScore());
393 double finalScore = fullScoreDoub - ((wrongAnswer * userSetOfQs.getIncorrectAnswerDeduction()))
394 - (emptyAnswer * userSetOfQs.getCorrectAnswerScore()) ;
395 if(userSetOfQs.getIncorrectAnswerDeduction() == 0){
396 finalScore = finalScore - (wrongAnswer * userSetOfQs.getCorrectAnswerScore());
397 }
398 userScoreLabel.setText(Double.toString(finalScore));
399 fullScoreLabel.setText(Double.toString(fullScoreDoub));
400 correctAnswer = 0;
401 wrongAnswer = 0;
402 emptyAnswer = 0;
403
404 }
405
406 /**
407 * @param args the command line arguments
408 */
409 /**
410 * @param args the command line arguments
411 */
412 public static void main(String args[]) {
413 /* Set the Nimbus look and feel */
414 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
415 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
416 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
417 */
418 try {
419 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
420 if ("Nimbus".equals(info.getName())) {
421 javax.swing.UIManager.setLookAndFeel(info.getClassName());
422 break;
423 }
424 }
425 } catch (ClassNotFoundException ex) {
426 java.util.logging.Logger.getLogger(TestingSessionPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
427 } catch (InstantiationException ex) {
428 java.util.logging.Logger.getLogger(TestingSessionPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
429 } catch (IllegalAccessException ex) {
430 java.util.logging.Logger.getLogger(TestingSessionPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
431 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
432 java.util.logging.Logger.getLogger(TestingSessionPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
433 }
434 //</editor-fold>
435 //</editor-fold>
436 //</editor-fold>
437 //</editor-fold>
438
439 /* Create and display the form */
440 java.awt.EventQueue.invokeLater(new Runnable() {
441 public void run() {
442 new TestingSessionPanel().setVisible(true);
443 }
444 });
445 }
446
448
449 //-----------------------------------------------------------------------------------------------
/*#######################################################################################################################################
##############################NOTE THAT ALL CODE WHICH IS HIGHLIGHTED BY THE GREY BLOCK IS AUTO-GENERATED FROM#################
##################################NETBEANS, (mainly the GUI stuff)#############################################################################
############################################################################################################################################
############################################################################################################################################
############################################################################################################################################
*/
447 /**
90 * This method is called from within the constructor to initialize the form.
91 * WARNING: Do NOT modify this code. The content of this method is always
92 * regenerated by the Form Editor.
93 */
94 @SuppressWarnings("unchecked")
95 // <editor-fold defaultstate="collapsed" desc="Generated Code">
96 private void initComponents() {
97
98 tPanel = new javax.swing.JPanel();
99 dismissButton = new javax.swing.JButton();
100 getResultButton = new javax.swing.JButton();
101 setOfQsNameLabel = new javax.swing.JLabel();
102 notesLabel = new javax.swing.JLabel();
103 testScrollPane = new javax.swing.JScrollPane();
104 testTable = new javax.swing.JTable();
105 userScoreLabel = new javax.swing.JLabel();
106 fullScoreLabel = new javax.swing.JLabel();
107 nameLabel = new javax.swing.JLabel();
108 youScoreLabel = new javax.swing.JLabel();
109 outOfLabel = new javax.swing.JLabel();
110 descriptionLabel = new javax.swing.JLabel();
111
112 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
113 setResizable(false);
114
115 dismissButton.setText("Dismiss");
116 dismissButton.addMouseListener(new java.awt.event.MouseAdapter() {
117 public void mouseReleased(java.awt.event.MouseEvent evt) {
118 dismissButtonMouseReleased(evt);
119 }
120 });
121 dismissButton.addActionListener(new java.awt.event.ActionListener() {
122 public void actionPerformed(java.awt.event.ActionEvent evt) {
123 dismissButtonActionPerformed(evt);
124 }
125 });
126
127 getResultButton.setText("Get result");
128 getResultButton.addMouseListener(new java.awt.event.MouseAdapter() {
129 public void mouseReleased(java.awt.event.MouseEvent evt) {
130 getResultButtonMouseReleased(evt);
131 }
132 });
133 getResultButton.addActionListener(new java.awt.event.ActionListener() {
134 public void actionPerformed(java.awt.event.ActionEvent evt) {
135 getResultButtonActionPerformed(evt);
136 }
137 });
138
139 setOfQsNameLabel.setFont(new java.awt.Font("Lucida Grande", 1, 13)); // NOI18N
140 setOfQsNameLabel.setText("Name ");
141
142 notesLabel.setText("Notes:");
143
144 testTable.setFont(new java.awt.Font("Segoe UI Symbol", 0, 14)); // NOI18N
145 testTable.setModel(new javax.swing.table.DefaultTableModel(
146 new Object [][] {
147 {null, null, null},
148 {null, null, null},
149 {null, null, null},
150 {null, null, null},
151 {null, null, null},
152 {null, null, null},
153 {null, null, null},
154 {null, null, null},
155 {null, null, null},
156 {null, null, null},
157 {null, null, null},
158 {null, null, null},
159 {null, null, null},
160 {null, null, null},
161 {null, null, null},
162 {null, null, null},
163 {null, null, null},
164 {null, null, null},
165 {null, null, null},
166 {null, null, null},
167 {null, null, null},
168 {null, null, null},
169 {null, null, null},
170 {null, null, null},
171 {null, null, null},
172 {null, null, null},
173 {null, null, null},
174 {null, null, null},
175 {null, null, null},
176 {null, null, null},
177 {null, null, null},
178 {null, null, null},
179 {null, null, null},
180 {null, null, null},
181 {null, null, null},
182 {null, null, null},
183 {null, null, null},
184 {null, null, null},
185 {null, null, null},
186 {null, null, null},
187 {null, null, null},
188 {null, null, null},
189 {null, null, null},
190 {null, null, null},
191 {null, null, null},
192 {null, null, null},
193 {null, null, null},
194 {null, null, null},
195 {null, null, null},
196 {null, null, null},
197 {null, null, null},
198 {null, null, null},
199 {null, null, null},
200 {null, null, null},
201 {null, null, null},
202 {null, null, null},
203 {null, null, null},
204 {null, null, null},
205 {null, null, null},
206 {null, null, null},
207 {null, null, null},
208 {null, null, null},
209 {null, null, null},
210 {null, null, null},
211 {null, null, null},
212 {null, null, null},
213 {null, null, null},
214 {null, null, null},
215 {null, null, null},
216 {null, null, null},
217 {null, null, null},
218 {null, null, null},
219 {null, null, null},
220 {null, null, null},
221 {null, null, null},
222 {null, null, null},
223 {null, null, null},
224 {null, null, null},
225 {null, null, null},
226 {null, null, null},
227 {null, null, null},
228 {null, null, null},
229 {null, null, null},
230 {null, null, null},
231 {null, null, null},
232 {null, null, null},
233 {null, null, null},
234 {null, null, null},
235 {null, null, null},
236 {null, null, null},
237 {null, null, null},
238 {null, null, null},
239 {null, null, null},
240 {null, null, null},
241 {null, null, null},
242 {null, null, null},
243 {null, null, null},
244 {null, null, null},
245 {null, null, null},
246 {null, null, null}
247 },
248 new String [] {
249 "Question", "Your Answer", "Answer Key"
250 }
251 ) {
252 Class[] types = new Class [] {
253 java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class
254 };
255
256 public Class getColumnClass(int columnIndex) {
257 return types [columnIndex];
258 }
259 });
260 testScrollPane.setViewportView(testTable);
261
262 userScoreLabel.setFont(new java.awt.Font("Monospaced", 1, 13)); // NOI18N
263 userScoreLabel.setText("N/A");
264
265 fullScoreLabel.setFont(new java.awt.Font("Monospaced", 1, 13)); // NOI18N
266 fullScoreLabel.setText("finalScore");
267
268 youScoreLabel.setText("You scored");
269
270 outOfLabel.setText("out of");
271
272 javax.swing.GroupLayout tPanelLayout = new javax.swing.GroupLayout(tPanel);
273 tPanel.setLayout(tPanelLayout);
274 tPanelLayout.setHorizontalGroup(
275 tPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
276 .addGroup(tPanelLayout.createSequentialGroup()
277 .addContainerGap()
278 .addGroup(tPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
279 .addComponent(dismissButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
280 .addComponent(getResultButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
281 .addGroup(tPanelLayout.createSequentialGroup()
282 .addComponent(testScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
283 .addGap(0, 0, Short.MAX_VALUE))
284 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tPanelLayout.createSequentialGroup()
285 .addGroup(tPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
286 .addComponent(notesLabel)
287 .addGroup(tPanelLayout.createSequentialGroup()
288 .addGap(55, 55, 55)
289 .addComponent(nameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE))
290 .addComponent(descriptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
291 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
292 .addGroup(tPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
293 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tPanelLayout.createSequentialGroup()
294 .addComponent(youScoreLabel)
295 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
296 .addComponent(userScoreLabel))
297 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tPanelLayout.createSequentialGroup()
298 .addComponent(outOfLabel)
299 .addGap(12, 12, 12)
300 .addComponent(fullScoreLabel)))))
301 .addContainerGap())
302 .addGroup(tPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
303 .addGroup(tPanelLayout.createSequentialGroup()
304 .addContainerGap()
305 .addComponent(setOfQsNameLabel)
306 .addContainerGap(429, Short.MAX_VALUE)))
307 );
308 tPanelLayout.setVerticalGroup(
309 tPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
310 .addGroup(tPanelLayout.createSequentialGroup()
311 .addContainerGap()
312 .addComponent(nameLabel)
313 .addGroup(tPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
314 .addGroup(tPanelLayout.createSequentialGroup()
315 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
316 .addGroup(tPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
317 .addComponent(youScoreLabel)
318 .addComponent(userScoreLabel))
319 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
320 .addGroup(tPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
321 .addComponent(outOfLabel)
322 .addComponent(fullScoreLabel)))
323 .addGroup(tPanelLayout.createSequentialGroup()
324 .addGap(25, 25, 25)
325 .addComponent(notesLabel)
326 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
327 .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)))
328 .addGap(18, 18, 18)
329 .addComponent(testScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 304, javax.swing.GroupLayout.PREFERRED_SIZE)
330 .addGap(18, 18, 18)
331 .addComponent(dismissButton)
332 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
333 .addComponent(getResultButton)
334 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
335 .addGroup(tPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
336 .addGroup(tPanelLayout.createSequentialGroup()
337 .addContainerGap()
338 .addComponent(setOfQsNameLabel)
339 .addContainerGap(481, Short.MAX_VALUE)))
340 );
341
342 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
343 getContentPane().setLayout(layout);
344 layout.setHorizontalGroup(
345 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
346 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
347 .addContainerGap(30, Short.MAX_VALUE)
348 .addComponent(tPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
349 .addGap(30, 30, 30))
350 );
351 layout.setVerticalGroup(
352 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
353 .addGroup(layout.createSequentialGroup()
354 .addGap(10, 10, 10)
355 .addComponent(tPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
356 .addContainerGap(42, Short.MAX_VALUE))
357 );
358
359 pack();
360 }// </editor-fold>
450 // Variables declaration - do not modify
451 private javax.swing.JLabel descriptionLabel;
452 private javax.swing.JButton dismissButton;
453 private javax.swing.JLabel fullScoreLabel;
454 private javax.swing.JButton getResultButton;
455 private javax.swing.JLabel nameLabel;
456 private javax.swing.JLabel notesLabel;
457 private javax.swing.JLabel outOfLabel;
458 private javax.swing.JLabel setOfQsNameLabel;
459 private javax.swing.JPanel tPanel;
460 private javax.swing.JScrollPane testScrollPane;
461 private javax.swing.JTable testTable;
462 private javax.swing.JLabel userScoreLabel;
463 private javax.swing.JLabel youScoreLabel;
464 // End of variables declaration
465 }
466