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.DonorRole; import Business.Employee.Employee; import Business.Enterprise.Enterprise; import Business.HormonalRecords.HormonalRecords; import Business.Organization.Organization; import Business.UserAccount.UserAccount; import Business.WorkQueue.DonorBloodTestWorkRequest; import java.awt.CardLayout; import java.awt.Color; import java.util.Date; import javax.swing.JOptionPane; 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.data.category.DefaultCategoryDataset; public class DonorRecordsJPanel extends javax.swing.JPanel { /** * Creates new form DonorRecordsJPanel */ private JPanel userProcessContainer; private Organization organization; private Enterprise enterprise; private UserAccount userAccount; DonorBloodTestWorkRequest donorRequest; public DonorRecordsJPanel(JPanel userProcessContainer, Enterprise enterprise, Organization organization, UserAccount userAccount) { initComponents(); this.userProcessContainer = userProcessContainer; this.userAccount = userAccount; this.organization = organization; this.enterprise = enterprise; valueLabel1.setText(userAccount.getUsername()); populateTable(); } public void populateTable() { DefaultTableModel dtm = (DefaultTableModel) donorHormoneLevelsJTbl.getModel(); dtm.setRowCount(0); for (Employee donor : organization.getEmployeeDirectory().getEmployeeList()) { if (donor.getName().equalsIgnoreCase(userAccount.getEmployee().getName())) { for (HormonalRecords hr : donor.getHormonalRecordsHistory().getHormonalRecordsList()) { Object row[] = new Object[5]; row[0] = hr; row[1] = hr.getLeutinizingHormoneLevels(); row[2] = hr.getFollicleStimulatingHormoneLevels(); row[3] = hr.gethCGLevels(); row[4] = hr.getTempDropIOT(); dtm.addRow(row); } } } } /** * 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() { jScrollPane1 = new javax.swing.JScrollPane(); donorHormoneLevelsJTbl = new javax.swing.JTable(); jLabel1 = new javax.swing.JLabel(); valueLabel1 = new javax.swing.JLabel(); backJBtn = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); donorHormoneLevelsJTbl.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null, null }, { null, null, null, null, null }, { null, null, null, null, null }, { null, null, null, null, null } }, new String[] { "Date", "Leutenizing Hormone Level", "Follicle Stimulating Hormones", "HCG Levels", "My BBT" }) { boolean[] canEdit = new boolean[] { false, false, false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); jScrollPane1.setViewportView(donorHormoneLevelsJTbl); add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 61, 618, 91)); jLabel1.setText("Welcome to your records:"); add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(23, 11, -1, -1)); valueLabel1.setText("<value>"); add(valueLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(153, 11, -1, -1)); backJBtn.setText("Back"); backJBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { backJBtnActionPerformed(evt); } }); add(backJBtn, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 196, 96, 34)); jButton1.setText("View Statistics"); 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(112, 196, -1, 34)); }// </editor-fold>//GEN-END:initComponents private void backJBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backJBtnActionPerformed userProcessContainer.remove(this); CardLayout layout = (CardLayout) userProcessContainer.getLayout(); layout.previous(userProcessContainer); }//GEN-LAST:event_backJBtnActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed int selectedRow = donorHormoneLevelsJTbl.getSelectedRow(); if (selectedRow >= 0) { double lHLevel = 0.0; double FSH = 0.0; double hcg = 0.0; for (Employee donor : organization.getEmployeeDirectory().getEmployeeList()) { if (donor.getName().equalsIgnoreCase(userAccount.getEmployee().getName())) { for (HormonalRecords hr : donor.getHormonalRecordsHistory().getHormonalRecordsList()) { //hr = (HormonalRecords)donorHormoneLevelsJTbl.getValueAt(selectedRow,0); lHLevel = hr.getLeutinizingHormoneLevels(); FSH = hr.getFollicleStimulatingHormoneLevels(); hcg = hr.gethCGLevels(); } DefaultCategoryDataset data = new DefaultCategoryDataset(); data.setValue(lHLevel, "Value", "LH level"); data.setValue(FSH, "Value", "FSH level"); data.setValue(hcg, "Value", "HCG level"); JFreeChart chart = ChartFactory.createBarChart3D("Hormonal Level Stats", "Hormonal Parameters", "Values", data); chart.setBackgroundPaint(Color.WHITE); chart.getTitle().setPaint(Color.BLUE); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.RED); ChartFrame frame = new ChartFrame("Bar Chart for Donor", chart); frame.setVisible(true); frame.setSize(450, 350); } } } else { JOptionPane.showMessageDialog(null, "Please select a row from the table", "Warning", JOptionPane.WARNING_MESSAGE); } }//GEN-LAST:event_jButton1ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton backJBtn; private javax.swing.JTable donorHormoneLevelsJTbl; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel valueLabel1; // End of variables declaration//GEN-END:variables }