/Users/johnr/Desktop/IA pdf Downloads/Criteria__P__-_Coding_Project_Upload_all_2022-05-03/ia2_Sorn/src/main/java/com/mycompany/ia2/mainGUI.java
  1 /*
  2  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
  3  * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/Application.java to edit this template
  4  */
  5 package com.mycompany.ia2;
  6 import java.awt.BorderLayout;
  7 import java.awt.Color;
  8 import java.util.LinkedList;
  9 import javax.swing.JOptionPane;
 10 import java.sql.*;
 11 import java.text.DecimalFormat;
 12 import javax.swing.table.*;
 13 import org.jfree.chart.ChartFactory;
 14 import org.jfree.chart.ChartPanel;
 15 import org.jfree.chart.JFreeChart;
 16 import org.jfree.chart.plot.CategoryPlot;
 17 import org.jfree.chart.plot.PlotOrientation;
 18 import org.jfree.chart.renderer.category.LineAndShapeRenderer;
 19 import org.jfree.data.category.DefaultCategoryDataset;
 20 
 21 
 22 /**
 23  *
 24  * @author 21015
 25  */
 26 public class mainGUI extends javax.swing.JFrame {
 27 
 28     /**
 29      * Creates new form mainGUI
 30      */
 31     
 32     //Initializing Stack and Linkedlist of UserStat Class
 33     LinkedList<UserStat> usStack = new LinkedList<UserStat>();
 34     LinkedList<UserStat> usLinkedList = new LinkedList<UserStat>();
 35     
 36     public mainGUI() {
 37         initComponents();
 38         
 39         //Updating the View Stat Page
 40         updateViewStat();
 41     }
 42     
 43     public void updateViewStat(){
 44         try{
 45             //Setting Decimal to 2 Places
 46             DecimalFormat dfSharp = new DecimalFormat("#.##");
 47     
 48             //Getting Match History Table
 49             DefaultTableModel mhTable = (DefaultTableModel) matchHistoryTable.getModel();
 50             
 51             //Set Row to 0 Inorder to Clear the Table
 52             mhTable.setRowCount(0);
 53             
 54             //Clearing User Stat LinkedList and Stack
 55             usLinkedList.clear();
 56             usStack.clear();
 57             
 58             //Initializing Variables to Store Total Number of Each Stat
 59             int totalKill = 0;
 60             int totalDeath = 0;
 61             int totalAssist = 0;
 62             int totalWin = 0;
 63             int totalGame = 0;
 64             int gameNumber = 1;
 65             
 66             //Connecting to MySql
 67             Class.forName("com.mysql.jdbc.Driver");
 68             Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/sys","root","12345678");
 69             
 70             //MySql Syntax for Selecting Data
 71             String sql = "select * from sys.user";
 72             
 73             //Creating Statement and Executing the MySql Syntax to Get the Data
 74             Statement stmt = con.createStatement();
 75             ResultSet rs = stmt.executeQuery(sql);
 76             
 77             //While There Is Still Data Left in MySql, Keeps Retrieving
 78             while(rs.next()){
 79                 //Getting the Agent's Name From MySql
 80                 String agent = rs.getString("agent");
 81                 
 82                 //Check If the User Wants to See Specific Agents's Match History and Stats
 83                 if(!agentFilterComboBox.getSelectedItem().equals("All")){
 84                     //Matching the Agent's Name that the User Wants to See With Data in MySql
 85                     if(agent.equals(agentFilterComboBox.getSelectedItem())){
 86                         
 87                         //Initializing Variables to Store Data From MySql
 88                         int kill = rs.getInt("pkill");
 89                         int death = rs.getInt("death");
 90                         int assist = rs.getInt("assist");
 91                         boolean win = rs.getBoolean("win");
 92                         int id = rs.getInt("id");
 93                         
 94                         //Storing These Data in UserStat Class
 95                         UserStat us = new UserStat(agent, kill, death, assist, win, gameNumber, id);
 96                         
 97                         //Adding MySql Data to the Total Stat Variables
 98                         totalGame += 1;
 99                         totalKill += kill;
100                         totalDeath += death;
101                         totalAssist += assist;
102                         gameNumber ++;
103                         
104                         //Check If that Game the User Won or Lost
105                         if(win){
106                             //If the User Won, Increase the Total Win by 1
107                             totalWin += 1;
108                         }
109                         
110                         //Pusing the UserStat Class Into User Stat Stack
111                         usStack.push(us);
112                         usLinkedList.add(us);
113                     }
114                 } else {
115                     //Initializing Variables to Store Data From MySql
116                     int kill = rs.getInt("pkill");
117                     int death = rs.getInt("death");
118                     int assist = rs.getInt("assist");
119                     boolean win = rs.getBoolean("win");
120                     int id = rs.getInt("id");
121                     
122                     //Storing These Data in UserStat Class
123                     UserStat us = new UserStat(agent, kill, death, assist, win, gameNumber, id);
124                     
125                     //Adding MySql Data to the Total Stat Variables
126                     totalGame += 1;
127                     totalKill += kill;
128                     totalDeath += death;
129                     totalAssist += assist;
130                     gameNumber ++;
131                     
132                     //Check If that Game the User Won or Lost
133                     if(win){
134                         //If the User Won, Increase the Total Win by 1
135                         totalWin += 1;
136                     }
137                     
138                     //Pusing the UserStat Class Into User Stat Stack
139                     usStack.push(us);
140                     usLinkedList.add(us);
141                 }
142             }
143             
144             //Initializing the KDA and Win Rate After Getting the Data Inorder to Avoid Dividing by Zero
145             double totalKDA = Double.parseDouble(dfSharp.format((double) (totalKill + totalAssist)/totalDeath));
146             double winRate = Double.parseDouble(dfSharp.format((double) totalWin/totalGame));
147             
148             //While User Stat Stack Is Not Empty, Keep Adding the Table
149             while(!usStack.isEmpty()){
150                 //Poping Data From User Stat Stack to the Match History Table
151                 mhTable.addRow(usStack.pop().getDataAsString());
152             }
153             
154             //Creating Dtatset for the Graph
155             DefaultCategoryDataset dataset = new DefaultCategoryDataset();
156             for(int i = 0; i < usLinkedList.size(); i ++){
157                 dataset.setValue(usLinkedList.get(i).calKDA(), "KDA", String.valueOf(i + 1));
158             }
159 
160             //Creating Chart
161             JFreeChart linechart = ChartFactory.createLineChart("","Game Number","KDA", dataset, PlotOrientation.VERTICAL, false, false, false);
162 
163             //Creating Plot Object
164             CategoryPlot lineCategoryPlot = linechart.getCategoryPlot();
165             // lineCategoryPlot.setRangeGridlinePaint(Color.BLUE);
166             lineCategoryPlot.setBackgroundPaint(Color.white);
167 
168             //Creating Render Object In Order to Change the Color of the Line
169             LineAndShapeRenderer lineRenderer = (LineAndShapeRenderer) lineCategoryPlot.getRenderer();
170             Color lineChartColor = new Color(0,102,204);
171             lineRenderer.setSeriesPaint(0, lineChartColor);
172 
173             //Displaying the Graph
174             ChartPanel lineChartPanel = new ChartPanel(linechart);
175             kdaGraph.removeAll();
176             kdaGraph.add(lineChartPanel, BorderLayout.CENTER);
177             kdaGraph.validate();
178             
179             //Setting the Text to Display the Stats
180             killLabel.setText("Total Kill: " + totalKill);
181             deathLabel.setText("Total Death: " + totalDeath);
182             assistLabel.setText("Total Assist: " + totalAssist);
183             kdaLabel.setText("KDA: " + totalKDA);
184             totalGameLabel.setText("Total Game: " + totalGame);
185             totalWinLabel.setText("Total Win: " + totalWin);
186             winRateLabel.setText("Win Rate: " + winRate);
187         } catch (Exception e){
188             //Printing Error
189             System.out.println("error");
190             System.out.println(e.getMessage());
191         }
192     }
193 
194     /**
195      * This method is called from within the constructor to initialize the form.
196      * WARNING: Do NOT modify this code. The content of this method is always
197      * regenerated by the Form Editor.
198      */
199     @SuppressWarnings("unchecked")
200     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
201     private void initComponents() {
202 
203         jTabbedPane2 = new javax.swing.JTabbedPane();
204         addStat = new javax.swing.JPanel();
205         jLabel1 = new javax.swing.JLabel();
206         jLabel2 = new javax.swing.JLabel();
207         jLabel3 = new javax.swing.JLabel();
208         jLabel4 = new javax.swing.JLabel();
209         jLabel5 = new javax.swing.JLabel();
210         killTextBox = new javax.swing.JTextField();
211         deathTextBox = new javax.swing.JTextField();
212         assistTextBox = new javax.swing.JTextField();
213         winLoseComboBox = new javax.swing.JComboBox<>();
214         agentComboBox = new javax.swing.JComboBox<>();
215         addButton = new javax.swing.JButton();
216         viewStat = new javax.swing.JPanel();
217         jScrollPane1 = new javax.swing.JScrollPane();
218         matchHistoryTable = new javax.swing.JTable();
219         refreshButton = new javax.swing.JButton();
220         killLabel = new javax.swing.JLabel();
221         deathLabel = new javax.swing.JLabel();
222         assistLabel = new javax.swing.JLabel();
223         kdaLabel = new javax.swing.JLabel();
224         totalWinLabel = new javax.swing.JLabel();
225         totalGameLabel = new javax.swing.JLabel();
226         winRateLabel = new javax.swing.JLabel();
227         jLabel6 = new javax.swing.JLabel();
228         agentFilterComboBox = new javax.swing.JComboBox<>();
229         removeButton = new javax.swing.JButton();
230         kdaGraph = new javax.swing.JPanel();
231         menuBar = new javax.swing.JMenuBar();
232         fileMenu = new javax.swing.JMenu();
233         openMenuItem = new javax.swing.JMenuItem();
234         saveMenuItem = new javax.swing.JMenuItem();
235         saveAsMenuItem = new javax.swing.JMenuItem();
236         exitMenuItem = new javax.swing.JMenuItem();
237         editMenu = new javax.swing.JMenu();
238         cutMenuItem = new javax.swing.JMenuItem();
239         copyMenuItem = new javax.swing.JMenuItem();
240         pasteMenuItem = new javax.swing.JMenuItem();
241         deleteMenuItem = new javax.swing.JMenuItem();
242         helpMenu = new javax.swing.JMenu();
243         contentsMenuItem = new javax.swing.JMenuItem();
244         aboutMenuItem = new javax.swing.JMenuItem();
245 
246         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
247 
248         jTabbedPane2.setBackground(new java.awt.Color(255, 255, 255));
249 
250         jLabel1.setText("Kill");
251 
252         jLabel2.setText("Death");
253 
254         jLabel3.setText("Assist");
255 
256         jLabel4.setText("Agent");
257 
258         jLabel5.setText("Win");
259 
260         killTextBox.addActionListener(new java.awt.event.ActionListener() {
261             public void actionPerformed(java.awt.event.ActionEvent evt) {
262                 killTextBoxActionPerformed(evt);
263             }
264         });
265 
266         winLoseComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "True", "False" }));
267         winLoseComboBox.addActionListener(new java.awt.event.ActionListener() {
268             public void actionPerformed(java.awt.event.ActionEvent evt) {
269                 winLoseComboBoxActionPerformed(evt);
270             }
271         });
272 
273         agentComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Brimstone", "Viper", "Omen", "Killjoy", "Cypher", "Sova", "Sage", "Phoenix", "Jett", "Reyna", "Razebreach", "Skye", "Yoru", "Astrsa", "KAY/O", "Chamber", "Neon" }));
274 
275         addButton.setText("Add");
276         addButton.addMouseListener(new java.awt.event.MouseAdapter() {
277             public void mouseClicked(java.awt.event.MouseEvent evt) {
278                 addButtonMouseClicked(evt);
279             }
280         });
281 
282         javax.swing.GroupLayout addStatLayout = new javax.swing.GroupLayout(addStat);
283         addStat.setLayout(addStatLayout);
284         addStatLayout.setHorizontalGroup(
285             addStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
286             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, addStatLayout.createSequentialGroup()
287                 .addContainerGap(260, Short.MAX_VALUE)
288                 .addGroup(addStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
289                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, addStatLayout.createSequentialGroup()
290                         .addGroup(addStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
291                             .addComponent(jLabel2)
292                             .addGroup(addStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
293                                 .addComponent(jLabel3)
294                                 .addGroup(addStatLayout.createSequentialGroup()
295                                     .addComponent(jLabel1)
296                                     .addGap(17, 17, 17)))
297                             .addComponent(jLabel5)
298                             .addComponent(jLabel4))
299                         .addGap(52, 52, 52)
300                         .addGroup(addStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
301                             .addComponent(winLoseComboBox, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
302                             .addComponent(assistTextBox, javax.swing.GroupLayout.Alignment.TRAILING)
303                             .addComponent(killTextBox)
304                             .addComponent(deathTextBox)
305                             .addComponent(agentComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)))
306                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, addStatLayout.createSequentialGroup()
307                         .addComponent(addButton)
308                         .addGap(121, 121, 121)))
309                 .addGap(255, 255, 255))
310         );
311         addStatLayout.setVerticalGroup(
312             addStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
313             .addGroup(addStatLayout.createSequentialGroup()
314                 .addGap(93, 93, 93)
315                 .addGroup(addStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
316                     .addGroup(addStatLayout.createSequentialGroup()
317                         .addGroup(addStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
318                             .addComponent(killTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
319                             .addComponent(jLabel1))
320                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
321                         .addComponent(deathTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
322                     .addComponent(jLabel2))
323                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
324                 .addGroup(addStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
325                     .addComponent(assistTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
326                     .addComponent(jLabel3))
327                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
328                 .addGroup(addStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
329                     .addComponent(winLoseComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
330                     .addComponent(jLabel5))
331                 .addGap(16, 16, 16)
332                 .addGroup(addStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
333                     .addComponent(agentComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
334                     .addComponent(jLabel4))
335                 .addGap(18, 18, 18)
336                 .addComponent(addButton)
337                 .addContainerGap(98, Short.MAX_VALUE))
338         );
339 
340         jTabbedPane2.addTab("Add Stat", addStat);
341 
342         matchHistoryTable.setAutoCreateRowSorter(true);
343         matchHistoryTable.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
344         matchHistoryTable.setModel(new javax.swing.table.DefaultTableModel(
345             new Object [][] {
346 
347             },
348             new String [] {
349                 "Game #", "Agent", "Kill", "Death", "Assist", "Win", "KDA"
350             }
351         ) {
352             boolean[] canEdit = new boolean [] {
353                 true, true, false, true, true, true, true
354             };
355 
356             public boolean isCellEditable(int rowIndex, int columnIndex) {
357                 return canEdit [columnIndex];
358             }
359         });
360         jScrollPane1.setViewportView(matchHistoryTable);
361 
362         refreshButton.setText("Refresh");
363         refreshButton.addMouseListener(new java.awt.event.MouseAdapter() {
364             public void mouseClicked(java.awt.event.MouseEvent evt) {
365                 refreshButtonMouseClicked(evt);
366             }
367         });
368 
369         killLabel.setText("Total Kill:");
370 
371         deathLabel.setText("Total Death:");
372 
373         assistLabel.setText("Total Assist:");
374 
375         kdaLabel.setText("KDA:");
376 
377         totalWinLabel.setText("Total Win: ");
378 
379         totalGameLabel.setText("Total Game:");
380 
381         winRateLabel.setText("Win Rate:");
382 
383         jLabel6.setText("Character:");
384 
385         agentFilterComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "All", "Brimstone", "Viper", "Omen", "Killjoy", "Cypher", "Sova", "Sage", "Phoenix", "Jett", "Reyna", "Razebreach", "Skye", "Yoru", "Astrsa", "KAY/O", "Chamber", "Neon" }));
386 
387         removeButton.setText("Remove");
388         removeButton.addMouseListener(new java.awt.event.MouseAdapter() {
389             public void mouseClicked(java.awt.event.MouseEvent evt) {
390                 removeButtonMouseClicked(evt);
391             }
392         });
393 
394         kdaGraph.setBackground(new java.awt.Color(255, 255, 255));
395         kdaGraph.setLayout(new java.awt.BorderLayout());
396 
397         javax.swing.GroupLayout viewStatLayout = new javax.swing.GroupLayout(viewStat);
398         viewStat.setLayout(viewStatLayout);
399         viewStatLayout.setHorizontalGroup(
400             viewStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
401             .addGroup(viewStatLayout.createSequentialGroup()
402                 .addGap(16, 16, 16)
403                 .addGroup(viewStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
404                     .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
405                     .addComponent(kdaGraph, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE))
406                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
407                 .addGroup(viewStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
408                     .addComponent(kdaLabel)
409                     .addGroup(viewStatLayout.createSequentialGroup()
410                         .addGroup(viewStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
411                             .addComponent(deathLabel)
412                             .addComponent(killLabel)
413                             .addComponent(assistLabel))
414                         .addGap(41, 41, 41)
415                         .addGroup(viewStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
416                             .addComponent(totalGameLabel)
417                             .addComponent(totalWinLabel)
418                             .addComponent(winRateLabel)))
419                     .addGroup(viewStatLayout.createSequentialGroup()
420                         .addGap(9, 9, 9)
421                         .addComponent(jLabel6)
422                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
423                         .addGroup(viewStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
424                             .addComponent(refreshButton)
425                             .addComponent(agentFilterComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
426                     .addComponent(removeButton))
427                 .addContainerGap(14, Short.MAX_VALUE))
428         );
429         viewStatLayout.setVerticalGroup(
430             viewStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
431             .addGroup(viewStatLayout.createSequentialGroup()
432                 .addGap(30, 30, 30)
433                 .addGroup(viewStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
434                     .addComponent(killLabel)
435                     .addComponent(totalWinLabel))
436                 .addGap(23, 23, 23)
437                 .addGroup(viewStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
438                     .addComponent(deathLabel)
439                     .addComponent(totalGameLabel))
440                 .addGap(25, 25, 25)
441                 .addGroup(viewStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
442                     .addComponent(assistLabel)
443                     .addComponent(winRateLabel))
444                 .addGap(29, 29, 29)
445                 .addComponent(kdaLabel)
446                 .addGap(25, 25, 25)
447                 .addGroup(viewStatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
448                     .addComponent(jLabel6)
449                     .addComponent(agentFilterComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
450                 .addGap(18, 18, 18)
451                 .addComponent(refreshButton)
452                 .addGap(52, 52, 52)
453                 .addComponent(removeButton)
454                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
455             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, viewStatLayout.createSequentialGroup()
456                 .addGap(14, 14, 14)
457                 .addComponent(kdaGraph, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
458                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
459                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
460                 .addGap(15, 15, 15))
461         );
462 
463         jTabbedPane2.addTab("View Stat", viewStat);
464 
465         fileMenu.setMnemonic('f');
466         fileMenu.setText("File");
467 
468         openMenuItem.setMnemonic('o');
469         openMenuItem.setText("Open");
470         fileMenu.add(openMenuItem);
471 
472         saveMenuItem.setMnemonic('s');
473         saveMenuItem.setText("Save");
474         fileMenu.add(saveMenuItem);
475 
476         saveAsMenuItem.setMnemonic('a');
477         saveAsMenuItem.setText("Save As ...");
478         saveAsMenuItem.setDisplayedMnemonicIndex(5);
479         fileMenu.add(saveAsMenuItem);
480 
481         exitMenuItem.setMnemonic('x');
482         exitMenuItem.setText("Exit");
483         exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
484             public void actionPerformed(java.awt.event.ActionEvent evt) {
485                 exitMenuItemActionPerformed(evt);
486             }
487         });
488         fileMenu.add(exitMenuItem);
489 
490         menuBar.add(fileMenu);
491 
492         editMenu.setMnemonic('e');
493         editMenu.setText("Edit");
494 
495         cutMenuItem.setMnemonic('t');
496         cutMenuItem.setText("Cut");
497         editMenu.add(cutMenuItem);
498 
499         copyMenuItem.setMnemonic('y');
500         copyMenuItem.setText("Copy");
501         editMenu.add(copyMenuItem);
502 
503         pasteMenuItem.setMnemonic('p');
504         pasteMenuItem.setText("Paste");
505         editMenu.add(pasteMenuItem);
506 
507         deleteMenuItem.setMnemonic('d');
508         deleteMenuItem.setText("Delete");
509         editMenu.add(deleteMenuItem);
510 
511         menuBar.add(editMenu);
512 
513         helpMenu.setMnemonic('h');
514         helpMenu.setText("Help");
515 
516         contentsMenuItem.setMnemonic('c');
517         contentsMenuItem.setText("Contents");
518         helpMenu.add(contentsMenuItem);
519 
520         aboutMenuItem.setMnemonic('a');
521         aboutMenuItem.setText("About");
522         helpMenu.add(aboutMenuItem);
523 
524         menuBar.add(helpMenu);
525 
526         setJMenuBar(menuBar);
527 
528         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
529         getContentPane().setLayout(layout);
530         layout.setHorizontalGroup(
531             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
532             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
533                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
534                 .addComponent(jTabbedPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 769, javax.swing.GroupLayout.PREFERRED_SIZE)
535                 .addContainerGap())
536         );
537         layout.setVerticalGroup(
538             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
539             .addGroup(layout.createSequentialGroup()
540                 .addContainerGap()
541                 .addComponent(jTabbedPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 468, javax.swing.GroupLayout.PREFERRED_SIZE)
542                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
543         );
544 
545         pack();
546     }// </editor-fold>                        
547 
548     private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                             
549         System.exit(0);
550     }                                            
551 
552     private void killTextBoxActionPerformed(java.awt.event.ActionEvent evt) {                                            
553         // TODO add your handling code here:
554     }                                           
555 
556     private void winLoseComboBoxActionPerformed(java.awt.event.ActionEvent evt) {                                                
557         // TODO add your handling code here:
558     }                                               
559 
560     private void addButtonMouseClicked(java.awt.event.MouseEvent evt) {                                       
561         
562         //Storing User's Input Into UserStat Class
563         UserStat us = new UserStat(agentComboBox.getSelectedItem().toString(), Integer.parseInt(killTextBox.getText()), Integer.parseInt(deathTextBox.getText()), Integer.parseInt(assistTextBox.getText()), Boolean.parseBoolean(winLoseComboBox.getSelectedItem().toString()));
564         
565         //Check If User Input Data In Every Textbox
566         if(killTextBox.getText().equals(null) || deathTextBox.getText().equals(null) || assistTextBox.getText().equals(null)){
567             //Display Message Dialog to User Saying that the User Needs to Fill In All the Textbox
568             JOptionPane.showMessageDialog(this, "Please Fill All the Boxes");
569         } else {
570             try{
571                 //Connecting to MySql
572                 Class.forName("com.mysql.jdbc.Driver");
573                 Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/sys","root","12345678");
574                 
575                 //MySql Syntax for Inserting with User's Input Dta
576                 String query = "INSERT INTO sys.user (pkill, death, assist, win, agent) VALUES (" + us.getKill() + ", " + us.getDeath() + ", " + us.getAssist() + ", " + us.getWin() + ", '" + us.getAgent() + "')";
577                 
578                 //Creating Statement and Executing the MySql Syntax
579                 Statement stmt = con.createStatement();
580                 stmt.executeUpdate(query);
581                 
582                 //Closing the Connection
583                 con.close();
584                 
585                 //Displaying Message Dialog that the Data Has Been Succesfully Added
586                 JOptionPane.showMessageDialog(this, "Added Successfully");
587                 
588                 //Reseting the Text Box and Combo Box
589                 killTextBox.setText("");
590                 deathTextBox.setText("");
591                 assistTextBox.setText("");
592                 winLoseComboBox.setSelectedIndex(0);
593                 agentComboBox.setSelectedIndex(0);
594                 
595                 //Updating View Stat Page
596                 updateViewStat();
597             } catch (Exception e){
598                 //Print Error
599                 System.out.println("error");
600                 System.out.println(e.getMessage());
601             }
602         }
603     }                                      
604 
605     private void refreshButtonMouseClicked(java.awt.event.MouseEvent evt) {                                           
606         //Displaying View Stat
607         updateViewStat();
608     }                                          
609 
610     private void removeButtonMouseClicked(java.awt.event.MouseEvent evt) {                                          
611         try{
612             //Initializing Object and Variables
613             DefaultTableModel mhTable = (DefaultTableModel) matchHistoryTable.getModel();
614             int selectedRow = matchHistoryTable.getSelectedRow();
615             int id = usLinkedList.get((usLinkedList.size() - selectedRow) - 1).getID();
616             
617             //Check How Many Row Are Selected
618             if(matchHistoryTable.getSelectedRowCount() == 1){
619                 //Remove the Row
620                 mhTable.removeRow(matchHistoryTable.getSelectedRow());
621                 
622             } else {
623                 JOptionPane.showMessageDialog(this, "Please Select Single Row For Delete");
624             }
625             
626             //Connecting to MySql
627             Class.forName("com.mysql.jdbc.Driver");
628             Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/sys","root","12345678");
629                 
630             //MySql Syntax for Deleting User's Input Dta
631             String query = "DELETE FROM sys.user WHERE id=" + id;
632                 
633             //Creating Statement and Executing the MySql Syntax
634             Statement stmt = con.createStatement();
635             stmt.executeUpdate(query);
636                 
637             //Closing the Connection
638             con.close();
639                 
640             //Displaying Message Dialog that the Data Has Been Succesfully Deleted
641             JOptionPane.showMessageDialog(this, "Deleted Successfully");
642             
643             //Displaying the View Stat
644             updateViewStat();
645         } catch (Exception e){
646             //Print Error
647             System.out.println("error");
648             System.out.println(e.getMessage());
649         }
650     }                                         
651 
652     /**
653      * @param args the command line arguments
654      */
655     public static void main(String args[]) {
656         /* Set the Nimbus look and feel */
657         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
658         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
659          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
660          */
661         try {
662             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
663                 if ("Nimbus".equals(info.getName())) {
664                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
665                     break;
666                 }
667             }
668         } catch (ClassNotFoundException ex) {
669             java.util.logging.Logger.getLogger(mainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
670         } catch (InstantiationException ex) {
671             java.util.logging.Logger.getLogger(mainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
672         } catch (IllegalAccessException ex) {
673             java.util.logging.Logger.getLogger(mainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
674         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
675             java.util.logging.Logger.getLogger(mainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
676         }
677         //</editor-fold>
678 
679         /* Create and display the form */
680         java.awt.EventQueue.invokeLater(new Runnable() {
681             public void run() {
682                 new mainGUI().setVisible(true);
683             }
684         });
685     }
686 
687     // Variables declaration - do not modify                     
688     private javax.swing.JMenuItem aboutMenuItem;
689     private javax.swing.JButton addButton;
690     private javax.swing.JPanel addStat;
691     private javax.swing.JComboBox<String> agentComboBox;
692     private javax.swing.JComboBox<String> agentFilterComboBox;
693     private javax.swing.JLabel assistLabel;
694     private javax.swing.JTextField assistTextBox;
695     private javax.swing.JMenuItem contentsMenuItem;
696     private javax.swing.JMenuItem copyMenuItem;
697     private javax.swing.JMenuItem cutMenuItem;
698     private javax.swing.JLabel deathLabel;
699     private javax.swing.JTextField deathTextBox;
700     private javax.swing.JMenuItem deleteMenuItem;
701     private javax.swing.JMenu editMenu;
702     private javax.swing.JMenuItem exitMenuItem;
703     private javax.swing.JMenu fileMenu;
704     private javax.swing.JMenu helpMenu;
705     private javax.swing.JLabel jLabel1;
706     private javax.swing.JLabel jLabel2;
707     private javax.swing.JLabel jLabel3;
708     private javax.swing.JLabel jLabel4;
709     private javax.swing.JLabel jLabel5;
710     private javax.swing.JLabel jLabel6;
711     private javax.swing.JScrollPane jScrollPane1;
712     private javax.swing.JTabbedPane jTabbedPane2;
713     private javax.swing.JPanel kdaGraph;
714     private javax.swing.JLabel kdaLabel;
715     private javax.swing.JLabel killLabel;
716     private javax.swing.JTextField killTextBox;
717     private javax.swing.JTable matchHistoryTable;
718     private javax.swing.JMenuBar menuBar;
719     private javax.swing.JMenuItem openMenuItem;
720     private javax.swing.JMenuItem pasteMenuItem;
721     private javax.swing.JButton refreshButton;
722     private javax.swing.JButton removeButton;
723     private javax.swing.JMenuItem saveAsMenuItem;
724     private javax.swing.JMenuItem saveMenuItem;
725     private javax.swing.JLabel totalGameLabel;
726     private javax.swing.JLabel totalWinLabel;
727     private javax.swing.JPanel viewStat;
728     private javax.swing.JComboBox<String> winLoseComboBox;
729     private javax.swing.JLabel winRateLabel;
730     // End of variables declaration                   
731 
732 }
733