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.MonitoringTeamRole; import Business.EcoSystem; import java.awt.CardLayout; import java.awt.Color; import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.JFreeChart; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; /** * * @author jayal */ public class EnvironmentJPanel extends javax.swing.JPanel { JPanel userProcessContainer; EcoSystem system; /** * Creates new form EnvironmentJPanel */ public EnvironmentJPanel(JPanel userProcessContainer, EcoSystem system) { initComponents(); this.userProcessContainer = userProcessContainer; this.system = system; } private PieDataset createDataset() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Critical Tickets", system.criticaltickets); dataset.setValue("High Tickets", system.hightickets); dataset.setValue("Medium Tickets", system.mediumtickets); return dataset; } /** * 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") private static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("Ticket statistics by severity", // chart title dataset, // data true, // include legend true, false); return chart; } // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jButton2 = new javax.swing.JButton(); setBackground(new java.awt.Color(255, 255, 255)); setLayout(null); jLabel1.setFont(new java.awt.Font("Tw Cen MT", 2, 18)); // NOI18N jLabel1.setForeground(new java.awt.Color(255, 0, 0)); jLabel1.setText("Vulnerabilities"); jLabel1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jLabel1MouseClicked(evt); } }); add(jLabel1); jLabel1.setBounds(290, 120, 98, 21); jButton2.setBackground(new java.awt.Color(255, 255, 255)); jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/home.png"))); // NOI18N jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); add(jButton2); jButton2.setBounds(30, 20, 83, 61); }// </editor-fold>//GEN-END:initComponents private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked // TODO add your handling code here: JFreeChart chart = createChart(createDataset()); chart.setBackgroundPaint(Color.YELLOW); chart.getTitle().setPaint(Color.red); ChartFrame frame = new ChartFrame("XYChart", chart); frame.setVisible(true); frame.setSize(450, 500); }//GEN-LAST:event_jLabel1MouseClicked private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: userProcessContainer.remove(this); CardLayout layout = (CardLayout) userProcessContainer.getLayout(); layout.previous(userProcessContainer); }//GEN-LAST:event_jButton2ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; // End of variables declaration//GEN-END:variables }