×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Alexandros Kyriazis
Added: Jan 25, 2022 6:46 PM
Views: 396
Tags: no tags
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package semesterprojectv5;
  7.  
  8. import com.google.gson.Gson;
  9. import com.google.gson.GsonBuilder;
  10. import com.google.gson.JsonArray;
  11. import com.google.gson.JsonElement;
  12. import com.google.gson.JsonObject;
  13. import java.text.SimpleDateFormat;
  14. import java.util.List;
  15. import javax.persistence.EntityManager;
  16. import javax.persistence.EntityManagerFactory;
  17. import javax.persistence.EntityTransaction;
  18. import javax.persistence.Persistence;
  19. import javax.persistence.Query;
  20. import javax.swing.DefaultComboBoxModel;
  21. import javax.swing.JOptionPane;
  22. import javax.swing.table.DefaultTableModel;
  23. import okhttp3.OkHttpClient;
  24. import okhttp3.Request;
  25.  
  26. /**
  27.  *
  28.  * @author alexa
  29.  */
  30. public class Showdata extends javax.swing.JFrame {
  31.  
  32.     EntityManagerFactory emf = Persistence.createEntityManagerFactory("Semesterprojectv5PU");
  33.     EntityManager em = emf.createEntityManager();
  34.     EntityTransaction tx = em.getTransaction();
  35.     CountryJpaController cjc = new CountryJpaController(emf);
  36.     CoviddataJpaController covjc = new CoviddataJpaController(emf);
  37.     public Showdata() {
  38.         initComponents();
  39.         PopulateTable1();
  40.           PopulateTable2();
  41.            PopulateTable3();
  42.        
  43.         List<Country> countries = cjc.findCountryEntities();
  44.  
  45.         DefaultComboBoxModel model = new DefaultComboBoxModel();
  46.  
  47.         for (Country c : countries) {
  48.             model.addElement(c.getName());
  49.         }
  50.         jComboBox1.setModel(model);
  51.  
  52.          List<Coviddata> dates = covjc.findCoviddataEntities();
  53.  
  54.         DefaultComboBoxModel modeldate = new DefaultComboBoxModel();
  55.  
  56.         for (Coviddata cov : dates) {
  57.             modeldate.addElement(cov.getTrndate());
  58.         }
  59.         jComboBox2.setModel(modeldate);
  60.         jComboBox3.setModel(modeldate);
  61.        
  62.        
  63.        
  64.        
  65.        
  66.        
  67.         //end
  68.        
  69.     }
  70.    
  71.     public void PopulateTable1(){
  72.          
  73.         DefaultTableModel tmodel = (DefaultTableModel) jTable1.getModel();
  74.    
  75.         tmodel.addColumn("Trndate");
  76.         tmodel.addColumn("Qty");
  77.         tmodel.addColumn("Proodqty");
  78.        
  79.         List<Coviddata> trndates = covjc.findCoviddataEntities();
  80.        
  81.           Object rowdata [] = new Object [3];
  82.          
  83.          
  84.          
  85.           for (Coviddata cov : trndates)  {
  86.              
  87.              
  88.               rowdata[0] = cov.getTrndate().toString();
  89.               rowdata[1] = cov.getQty();
  90.               rowdata[2] = cov.getProodqty();
  91.            tmodel.addRow(rowdata);
  92.              
  93.               }
  94.              
  95.        
  96.          
  97.          
  98.      
  99.        
  100.    
  101.    
  102.    
  103.    
  104.     }
  105.    
  106.     public void PopulateTable2(){
  107.          
  108.         DefaultTableModel tmodel = (DefaultTableModel) jTable2.getModel();
  109.    
  110.         tmodel.addColumn("Trndate");
  111.         tmodel.addColumn("Qty");
  112.         tmodel.addColumn("Proodqty");
  113.        
  114.         List<Coviddata> trndates = covjc.findCoviddataEntities();
  115.        
  116.           Object rowdata [] = new Object [3];
  117.          
  118.          
  119.          
  120.           for (Coviddata cov : trndates)  {
  121.              
  122.              
  123.               rowdata[0] = cov.getTrndate().toString();
  124.               rowdata[1] = cov.getQty();
  125.               rowdata[2] = cov.getProodqty();
  126.            tmodel.addRow(rowdata);
  127.              
  128.               }
  129.              
  130.        
  131.          
  132.          
  133.      
  134.        
  135.    
  136.    
  137.    
  138.    
  139.     }
  140.    
  141. public void PopulateTable3(){
  142.          
  143.         DefaultTableModel tmodel = (DefaultTableModel) jTable3.getModel();
  144.    
  145.         tmodel.addColumn("Trndate");
  146.         tmodel.addColumn("Qty");
  147.         tmodel.addColumn("Proodqty");
  148.        
  149.         List<Coviddata> trndates = covjc.findCoviddataEntities();
  150.        
  151.           Object rowdata [] = new Object [3];
  152.          
  153.          
  154.          
  155.           for (Coviddata cov : trndates)  {
  156.              
  157.              
  158.               rowdata[0] = cov.getTrndate().toString();
  159.               rowdata[1] = cov.getQty();
  160.               rowdata[2] = cov.getProodqty();
  161.            tmodel.addRow(rowdata);
  162.              
  163.               }
  164.              
  165.        
  166.          
  167.          
  168.      
  169.        
  170.    
  171.    
  172.    
  173.    
  174.     }
  175.    
  176.    
  177.     /**
  178.      * This method is called from within the constructor to initialize the form.
  179.      * WARNING: Do NOT modify this code. The content of this method is always
  180.      * regenerated by the Form Editor.
  181.      */
  182.     @SuppressWarnings("unchecked")
  183.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  184.     private void initComponents() {
  185.  
  186.         jLabel1 = new javax.swing.JLabel();
  187.         jComboBox1 = new javax.swing.JComboBox<>();
  188.         jLabel2 = new javax.swing.JLabel();
  189.         jComboBox2 = new javax.swing.JComboBox<>();
  190.         jLabel3 = new javax.swing.JLabel();
  191.         jComboBox3 = new javax.swing.JComboBox<>();
  192.         jComboBox4 = new javax.swing.JComboBox<>();
  193.         jButton1 = new javax.swing.JButton();
  194.         jButton2 = new javax.swing.JButton();
  195.         jButton3 = new javax.swing.JButton();
  196.         jScrollPane1 = new javax.swing.JScrollPane();
  197.         jTable1 = new javax.swing.JTable();
  198.         jScrollPane2 = new javax.swing.JScrollPane();
  199.         jTable2 = new javax.swing.JTable();
  200.         jScrollPane3 = new javax.swing.JScrollPane();
  201.         jTable3 = new javax.swing.JTable();
  202.  
  203.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  204.  
  205.         jLabel1.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
  206.         jLabel1.setText("Select Country");
  207.  
  208.         jComboBox1.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
  209.         jComboBox1.setMaximumRowCount(300);
  210.         jComboBox1.setModel(jComboBox1.getModel());
  211.         jComboBox1.addActionListener(new java.awt.event.ActionListener() {
  212.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  213.                 jComboBox1ActionPerformed(evt);
  214.             }
  215.         });
  216.  
  217.         jLabel2.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
  218.         jLabel2.setText("from Date");
  219.  
  220.         jComboBox2.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
  221.         jComboBox2.addActionListener(new java.awt.event.ActionListener() {
  222.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  223.                 jComboBox2ActionPerformed(evt);
  224.             }
  225.         });
  226.  
  227.         jLabel3.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
  228.         jLabel3.setText("to Date");
  229.  
  230.         jComboBox3.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
  231.         jComboBox3.addActionListener(new java.awt.event.ActionListener() {
  232.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  233.                 jComboBox3ActionPerformed(evt);
  234.             }
  235.         });
  236.  
  237.         jComboBox4.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
  238.         jComboBox4.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Complite Chart", "Deaths", "Confirmed Cases", "Recovered" }));
  239.  
  240.         jButton1.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
  241.         jButton1.setText("Chart View");
  242.  
  243.         jButton2.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
  244.         jButton2.setText("View on Google maps");
  245.  
  246.         jButton3.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
  247.         jButton3.setText("Delete Data");
  248.  
  249.         jTable1.setModel(new javax.swing.table.DefaultTableModel(
  250.             new Object [][] {
  251.                 {},
  252.                 {},
  253.                 {},
  254.                 {}
  255.             },
  256.             new String [] {
  257.  
  258.             }
  259.         ));
  260.         jScrollPane1.setViewportView(jTable1);
  261.         jTable1.getAccessibleContext().setAccessibleName("");
  262.  
  263.         jTable2.setModel(new javax.swing.table.DefaultTableModel(
  264.             new Object [][] {
  265.                 {},
  266.                 {},
  267.                 {},
  268.                 {}
  269.             },
  270.             new String [] {
  271.  
  272.             }
  273.         ));
  274.         jScrollPane2.setViewportView(jTable2);
  275.  
  276.         jTable3.setModel(new javax.swing.table.DefaultTableModel(
  277.             new Object [][] {
  278.                 {},
  279.                 {},
  280.                 {},
  281.                 {}
  282.             },
  283.             new String [] {
  284.  
  285.             }
  286.         ));
  287.         jScrollPane3.setViewportView(jTable3);
  288.  
  289.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  290.         getContentPane().setLayout(layout);
  291.         layout.setHorizontalGroup(
  292.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  293.             .addGroup(layout.createSequentialGroup()
  294.                 .addContainerGap()
  295.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  296.                     .addComponent(jButton2)
  297.                     .addComponent(jLabel1)
  298.                     .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
  299.                     .addComponent(jLabel2)
  300.                     .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  301.                     .addComponent(jLabel3)
  302.                     .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  303.                     .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  304.                     .addComponent(jButton1))
  305.                 .addGap(65, 65, 65)
  306.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  307.                     .addComponent(jButton3)
  308.                     .addGroup(layout.createSequentialGroup()
  309.                         .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE)
  310.                         .addGap(18, 18, 18)
  311.                         .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)
  312.                         .addGap(18, 18, 18)
  313.                         .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)))
  314.                 .addContainerGap(55, Short.MAX_VALUE))
  315.         );
  316.         layout.setVerticalGroup(
  317.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  318.             .addGroup(layout.createSequentialGroup()
  319.                 .addGap(31, 31, 31)
  320.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  321.                     .addGroup(layout.createSequentialGroup()
  322.                         .addComponent(jLabel1)
  323.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  324.                         .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  325.                         .addGap(45, 45, 45)
  326.                         .addComponent(jLabel2)
  327.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  328.                         .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  329.                         .addGap(45, 45, 45)
  330.                         .addComponent(jLabel3)
  331.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  332.                         .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  333.                         .addGap(100, 100, 100)
  334.                         .addComponent(jButton1)
  335.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  336.                         .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  337.                     .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  338.                     .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  339.                     .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  340.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
  341.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  342.                     .addComponent(jButton2)
  343.                     .addComponent(jButton3))
  344.                 .addGap(72, 72, 72))
  345.         );
  346.  
  347.         pack();
  348.     }// </editor-fold>                        
  349.  
  350.     private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  351.      
  352.     }                                          
  353.  
  354.     private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  355.         // TODO add your handling code here:
  356.     }                                          
  357.  
  358.     private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  359.         // TODO add your handling code here:
  360.     }                                          
  361.  
  362.     /**
  363.      * @param args the command line arguments
  364.      */
  365.     public static void main(String args[]) {
  366.         /* Set the Nimbus look and feel */
  367.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  368.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  369.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  370.          */
  371.         try {
  372.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  373.                 if ("Nimbus".equals(info.getName())) {
  374.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  375.                     break;
  376.                 }
  377.             }
  378.         } catch (ClassNotFoundException ex) {
  379.             java.util.logging.Logger.getLogger(Showdata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  380.         } catch (InstantiationException ex) {
  381.             java.util.logging.Logger.getLogger(Showdata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  382.         } catch (IllegalAccessException ex) {
  383.             java.util.logging.Logger.getLogger(Showdata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  384.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  385.             java.util.logging.Logger.getLogger(Showdata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  386.         }
  387.         //</editor-fold>
  388.  
  389.         /* Create and display the form */
  390.         java.awt.EventQueue.invokeLater(new Runnable() {
  391.             public void run() {
  392.                 new Showdata().setVisible(true);
  393.             }
  394.         });
  395.     }
  396.  
  397.     // Variables declaration - do not modify                    
  398.     private javax.swing.JButton jButton1;
  399.     private javax.swing.JButton jButton2;
  400.     private javax.swing.JButton jButton3;
  401.     private javax.swing.JComboBox<String> jComboBox1;
  402.     private javax.swing.JComboBox<String> jComboBox2;
  403.     private javax.swing.JComboBox<String> jComboBox3;
  404.     private javax.swing.JComboBox<String> jComboBox4;
  405.     private javax.swing.JLabel jLabel1;
  406.     private javax.swing.JLabel jLabel2;
  407.     private javax.swing.JLabel jLabel3;
  408.     private javax.swing.JScrollPane jScrollPane1;
  409.     private javax.swing.JScrollPane jScrollPane2;
  410.     private javax.swing.JScrollPane jScrollPane3;
  411.     private javax.swing.JTable jTable1;
  412.     private javax.swing.JTable jTable2;
  413.     private javax.swing.JTable jTable3;
  414.     // End of variables declaration                  
  415. }
  416.