userInterface.MonitoringTeamRole.DashBoarJPanel.java Source code

Java tutorial

Introduction

Here is the source code for userInterface.MonitoringTeamRole.DashBoarJPanel.java

Source

/*
 * 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 DashBoarJPanel extends javax.swing.JPanel {
    JPanel userProcessContainer;
    EcoSystem system;

    /**
     * Creates new form DashBoarJPanel
     */
    public DashBoarJPanel(JPanel userProcessContainer, EcoSystem system) {
        initComponents();

        this.userProcessContainer = userProcessContainer;
        this.system = system;

    }

    /**
     * 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.
     */

    private PieDataset createDataset() {
        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("Failed Attempts", system.numberofunsuccessfulevents);
        dataset.setValue("Successful atempts", system.numberofsuccessfulevents);
        return dataset;

    }

    private PieDataset createDataset1() {
        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("Open Tickets", system.opentickets);
        dataset.setValue("Closed Tickets", system.closedTickets);
        return dataset;

    }

    private static JFreeChart createChart(PieDataset dataset) {
        JFreeChart chart = ChartFactory.createPieChart("Successful authentication login vs failed login events", // chart title 
                dataset, // data    
                true, // include legend   
                true, false);

        return chart;
    }

    private static JFreeChart createChart1(PieDataset dataset1) {
        JFreeChart chart = ChartFactory.createPieChart("Ticket Status", // chart title 
                dataset1, // data    
                true, // include legend   
                true, false);

        return chart;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel3 = 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("Sucessful Authentication Login Vs Failed Login Events");
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
        });
        add(jLabel1);
        jLabel1.setBounds(167, 200, 380, 21);

        jLabel3.setFont(new java.awt.Font("Tw Cen MT", 2, 18)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 0, 0));
        jLabel3.setText("Ticket Status");
        jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel3MouseClicked(evt);
            }
        });
        add(jLabel3);
        jLabel3.setBounds(290, 150, 110, 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(20, 10, 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 jLabel3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel3MouseClicked
        // TODO add your handling code here:

        JFreeChart chart1 = createChart1(createDataset1());
        chart1.setBackgroundPaint(Color.YELLOW);
        chart1.getTitle().setPaint(Color.red);

        ChartFrame frame = new ChartFrame("XYChart", chart1);
        frame.setVisible(true);
        frame.setSize(450, 500);
    }//GEN-LAST:event_jLabel3MouseClicked

    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;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration//GEN-END:variables
}