Java tutorial
/* * 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 userinterface.AdministratorWorkArea; import Business.Employee.Employee; import Business.Enterprise.Enterprise; import Business.Organization.AdminOrganization; import Business.Organization.DoctorOrganization; import Business.Organization.Organization; import Business.Organization.PatientOrganization; import Business.UserAccount.UserAccount; import java.awt.CardLayout; import java.awt.Color; import java.util.ArrayList; import javax.swing.JPanel; import javax.swing.table.DefaultTableModel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; /** * * @author Neelu */ public class PopularDoctorJPanel extends javax.swing.JPanel { private JPanel userProcessContainer; private Enterprise enterprise; private UserAccount userAccount; private Organization docOrg; private Organization patOrg; private Employee doc1; private Employee doc2; private Employee doc3; private ArrayList<Employee> topDocList = new ArrayList<>(); /** * Creates new form PopularDoctorJPanel */ public PopularDoctorJPanel(JPanel upc, Enterprise e, UserAccount ua) { initComponents(); userProcessContainer = upc; userAccount = ua; enterprise = e; populateTable(); } public void populateTable() { int max1 = Integer.MIN_VALUE; int max2 = Integer.MIN_VALUE; int max3 = Integer.MIN_VALUE; for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof DoctorOrganization) { docOrg = organization; break; } } if (docOrg != null) { for (Employee doctor : docOrg.getEmployeeDirectory().getEmployeeList()) { if (doctor.getPatientCount() > max1) { max3 = max2; max2 = max1; max1 = doctor.getPatientCount(); doc3 = doc2; doc2 = doc1; doc1 = doctor; } else if (doctor.getPatientCount() > max2 && doctor.getPatientCount() <= max1) { max3 = max2; max2 = doctor.getPatientCount(); doc3 = doc2; doc2 = doctor; } else if (doctor.getPatientCount() <= max2 && doctor.getPatientCount() > max3) { max3 = doctor.getPatientCount(); doc3 = doctor; } } if (doc3 != null && doc2 != null && doc1 != null) { topDocList.add(doc1); topDocList.add(doc2); topDocList.add(doc3); } else if (doc2 != null && doc1 != null) { topDocList.add(doc1); topDocList.add(doc2); } else if (doc1 != null) { topDocList.add(doc1); } // topDocList.add(doc1); // topDocList.add(doc2); // topDocList.add(doc3); } DefaultTableModel dtm = (DefaultTableModel) doctorTable.getModel(); int rowcount = doctorTable.getRowCount(); for (int i = rowcount - 1; i >= 0; i--) { dtm.removeRow(i); } if (topDocList != null) { for (Employee doctor : topDocList) { Object row[] = new Object[2]; row[0] = doctor == null ? "No Doctors in the Organization" : doctor; row[1] = doctor == null ? " " : doctor.getPatientCount(); dtm.addRow(row); } } else { return; } } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); doctorTable = new javax.swing.JTable(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 36)); // NOI18N jLabel1.setText("Most Popular Doctors in the Hospital"); add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 20, -1, -1)); doctorTable.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N doctorTable.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null }, { null, null }, { null, null }, { null, null } }, new String[] { "Doctor Name", "Number of Patients Under Addmission" })); jScrollPane1.setViewportView(doctorTable); add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 130, 830, 170)); jButton1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jButton1.setText("<<Back"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 470, -1, -1)); jButton2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jButton2.setText("Bar Chart"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 340, 129, -1)); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: userProcessContainer.remove(this); CardLayout cardLayout = (CardLayout) userProcessContainer.getLayout(); cardLayout.previous(userProcessContainer); }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); int i = 1; for (Employee doctor : docOrg.getEmployeeDirectory().getEmployeeList()) { dataSet.setValue(doctor.getPatientCount(), "Number of Patients Assigned to the Doctor", doctor.getName()); i++; } JFreeChart chart = ChartFactory.createBarChart("Doctor Patient Graph", "Doctor Name", "Number Of Patients", dataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame("Number of Patients Assigned to the Doctor", chart); frame.setVisible(true); frame.setSize(800, 550); }//GEN-LAST:event_jButton2ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTable doctorTable; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables }