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.PowerStationAdminRole; import Business.Electricity.Electricity; import Business.Enterprise.EnergyEnterprise; import Business.Enterprise.Enterprise; import Business.Order.MasterOrderCatalog; import Business.Order.Order; import Business.Order.OrderItem; import Business.Organization.Organization; import java.awt.CardLayout; import java.awt.Color; import java.util.Collections; 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.PiePlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; public class ReviewPerformanceJPanel extends javax.swing.JPanel { private JPanel userProcessContainer; private Organization organization; private EnergyEnterprise enterprise; private MasterOrderCatalog masterOrderCatalog; /** * Creates new form ReviewVaccinePerformanceJPanel */ public ReviewPerformanceJPanel(JPanel userProcessContainer, Organization organization, Enterprise enterprise) { initComponents(); this.userProcessContainer = userProcessContainer; this.organization = organization; this.enterprise = (EnergyEnterprise) enterprise; this.masterOrderCatalog = masterOrderCatalog; // masterOrderCatalog.addOrder(order); int temp = 0; //populate(); // populateRank(); Collections.sort(organization.getElectricityDirectory().getElecCatalog()); int i = 0; for (Electricity e : organization.getElectricityDirectory().getElecCatalog()) { topElectricitySourceJTextField.setText(e.getElectricitySource()); //e.getNonPeakHourPrice(); i++; if (i == 1) { break; } } DefaultTableModel dtm = (DefaultTableModel) reviewJTable.getModel(); dtm.setRowCount(0); Collections.sort(organization.getElectricityDirectory().getElecCatalog()); int j = 0; for (Electricity e : organization.getElectricityDirectory().getElecCatalog()) { Object row[] = new Object[2]; row[0] = e; row[1] = e.getSoldQuantity(); dtm.addRow(row); } Collections.sort(organization.getElectricityDirectory().getElecCatalog()); int k = 0; for (Electricity e : organization.getElectricityDirectory().getElecCatalog()) { topSalesAmountJTextField.setText(String.valueOf(e.getNonPeakHourPrice())); //e.getNonPeakHourPrice(); k++; if (k == 1) { break; } } Collections.sort(organization.getElectricityDirectory().getElecCatalog()); int l = 0; for (Electricity e : organization.getElectricityDirectory().getElecCatalog()) { l += e.getSoldQuantity(); noOfProductSoldJTextField.setText(String.valueOf(l)); } } /** * 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(); reviewJTable = new javax.swing.JTable(); jLabel1 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); topSalesAmountJTextField = new javax.swing.JTextField(); noOfProductSoldJTextField = new javax.swing.JTextField(); backJButton = new javax.swing.JButton(); jLabel6 = new javax.swing.JLabel(); topElectricitySourceJTextField = new javax.swing.JTextField(); chartJButton = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); setBackground(new java.awt.Color(255, 255, 204)); reviewJTable.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null }, { null, null }, { null, null }, { null, null } }, new String[] { "Electricity", "Quantity Sold" }) { boolean[] canEdit = new boolean[] { false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); jScrollPane1.setViewportView(reviewJTable); jLabel1.setText("Top Sales Amount"); jLabel5.setText("Quantity of Electricity Sold"); backJButton.setText("<<Back"); backJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { backJButtonActionPerformed(evt); } }); jLabel6.setText("Top Energy Source"); chartJButton.setText("CHART"); chartJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { chartJButtonActionPerformed(evt); } }); jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N jLabel2.setText(" REVIEW PERFORMANCE"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(308, 308, 308).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel6) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(layout.createSequentialGroup().addComponent(backJButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(chartJButton)) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1).addComponent(jLabel5)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(noOfProductSoldJTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE) .addComponent(topSalesAmountJTextField) .addComponent(topElectricitySourceJTextField)))))) .addGroup(layout.createSequentialGroup().addGap(234, 234, 234).addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 461, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(763, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(21, 21, 21).addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(56, 56, 56) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1).addComponent(topSalesAmountJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(30, 30, 30) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6).addComponent(topElectricitySourceJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(43, 43, 43) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(noOfProductSoldJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5)) .addGap(103, 103, 103) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(backJButton).addComponent(chartJButton)) .addContainerGap(279, Short.MAX_VALUE))); }// </editor-fold>//GEN-END:initComponents private void backJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backJButtonActionPerformed // TODO add your handling code here: userProcessContainer.remove(this); CardLayout layout = (CardLayout) userProcessContainer.getLayout(); layout.previous(userProcessContainer); }//GEN-LAST:event_backJButtonActionPerformed private void chartJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chartJButtonActionPerformed // TODO add your handling code here: DefaultPieDataset d = new DefaultPieDataset(); Collections.sort(organization.getElectricityDirectory().getElecCatalog()); for (Electricity v : organization.getElectricityDirectory().getElecCatalog()) { d.setValue(v.getElectricitySource(), v.getSoldQuantity()); JFreeChart chart = ChartFactory.createPieChart("Pie Chart", d, true, true, true); PiePlot p = (PiePlot) chart.getPlot(); ChartFrame frame = new ChartFrame("Pie Chart", chart); frame.setVisible(true); frame.setSize(450, 500); // DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // int i=0; // for(Electricity v : organization.getElectricityDirectory().getElecCatalog()){ // // for(Order o : enterprise.getMasterOrderCatalog().getOrderCatalog()){ // for(OrderItem oi : organization.getOrder().getOrderItemList()){ // // // for(OrderItem oi : o.getOrderItemList()){ // if(oi.getElectricity().getElectricitySource().equals(v.getElectricitySource())) // { // i++; // // int totalSales = oi.getSalesPrice(); // topSalesAmountJTextField.getText(); // // // dataset.setValue(totalSales,"Values","product"+i); // } // // // JFreeChart chart = ChartFactory.createLineChart("Parameter values","Total Sales","Values",dataset); // chart.setBackgroundPaint(Color.white); // chart.getTitle().setPaint(Color.red); // CategoryPlot a = chart.getCategoryPlot(); // a.setRangeGridlinePaint(Color.blue); // ChartFrame frame = new ChartFrame("Line Chart For Parameters",chart); // frame.setVisible(true); // frame.setSize(450,350); // } }//GEN-LAST:event_chartJButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton backJButton; private javax.swing.JButton chartJButton; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField noOfProductSoldJTextField; private javax.swing.JTable reviewJTable; private javax.swing.JTextField topElectricitySourceJTextField; private javax.swing.JTextField topSalesAmountJTextField; // End of variables declaration//GEN-END:variables }