Gui.admin.NouveauStatistique.java Source code

Java tutorial

Introduction

Here is the source code for Gui.admin.NouveauStatistique.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 Gui.admin;

import com.tn.connect.MyConnection;
import com.tn.doa.EvaluationDAO;
import com.tn.tableModel.EvaluationTable;
import java.awt.Color;
import java.io.File;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.RectangleAnchor;

/**
 *
 * @author majdi
 */
public class NouveauStatistique extends javax.swing.JPanel {

    /**
     * Creates new form NouveauStatistique
     */
    public NouveauStatistique() {
        initComponents();
    }

/**
 * 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() {

    jPanel1 = new javax.swing.JPanel();
    jScrollPane1 = new javax.swing.JScrollPane();
    tablemesEvaluation = new javax.swing.JTable();
    jPanel4 = new javax.swing.JPanel();
    StatistiquesBoutton = new javax.swing.JButton();
    jLabel1 = new javax.swing.JLabel();
    jPanel3 = new javax.swing.JPanel();
    idEvaluationLabel = new javax.swing.JLabel();
    idEvaluationText = new javax.swing.JTextField();
    idAdherentevalueLabel = new javax.swing.JLabel();
    idAdherentEvaluText = new javax.swing.JTextField();
    idEvaluateurText = new javax.swing.JTextField();
    idEvaluateurLabel = new javax.swing.JLabel();
    noteLabel = new javax.swing.JLabel();
    noteTxt = new javax.swing.JTextField();
    commentaireTxt = new javax.swing.JTextField();
    commentaireLabel = new javax.swing.JLabel();
    RepTxt = new javax.swing.JTextField();
    ReponseLabel = new javax.swing.JLabel();

    setMaximumSize(new java.awt.Dimension(400, 300));
    setMinimumSize(new java.awt.Dimension(400, 300));
    setLayout(new java.awt.CardLayout());

    jPanel1.setMaximumSize(new java.awt.Dimension(591, 457));
    jPanel1.setMinimumSize(new java.awt.Dimension(591, 457));

    tablemesEvaluation.setModel(new  com.tn.tableModel.EvaluationTable());
    tablemesEvaluation.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            tablemesEvaluationMouseClicked(evt);
        }
    });
    jScrollPane1.setViewportView(tablemesEvaluation);

    jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Generer Les Statistiques ", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Tahoma", 3, 14))); // NOI18N

    StatistiquesBoutton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/StatistiquesIIcon.png"))); // NOI18N
    StatistiquesBoutton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            StatistiquesBouttonActionPerformed(evt);
        }
    });

    jLabel1.setText("Generer Les Statistiques ici :");

    javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
    jPanel4.setLayout(jPanel4Layout);
    jPanel4Layout.setHorizontalGroup(
        jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
            .addComponent(jLabel1)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 164, Short.MAX_VALUE)
            .addComponent(StatistiquesBoutton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
    );
    jPanel4Layout.setVerticalGroup(
        jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel1)
                .addComponent(StatistiquesBoutton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap())
    );

    jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Informations", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 3, 14))); // NOI18N

    idEvaluationLabel.setText("Id Evaluation :");

    idEvaluationText.setEditable(false);

    idAdherentevalueLabel.setText("Id Adhrent Evalu :");

    idAdherentEvaluText.setEditable(false);

    idEvaluateurText.setEditable(false);

    idEvaluateurLabel.setText("Id Evaluateur :");

    noteLabel.setText("Note :");

    noteTxt.setEditable(false);

    commentaireTxt.setEditable(false);

    commentaireLabel.setText("Commentaire :");

    RepTxt.setEditable(false);

    ReponseLabel.setText("Rponse:");

    javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel3Layout.createSequentialGroup()
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(idAdherentevalueLabel)
                        .addComponent(idEvaluationLabel)
                        .addComponent(idEvaluateurLabel))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(idAdherentEvaluText, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
                        .addComponent(idEvaluationText, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(idEvaluateurText)))
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(noteLabel)
                        .addComponent(commentaireLabel)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(ReponseLabel)))
                    .addGap(34, 34, 34)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(noteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(commentaireTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE)
                        .addComponent(RepTxt))))
            .addContainerGap(69, Short.MAX_VALUE))
    );
    jPanel3Layout.setVerticalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel3Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(idEvaluationLabel)
                .addComponent(idEvaluationText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(idAdherentevalueLabel)
                .addComponent(idAdherentEvaluText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(idEvaluateurText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(idEvaluateurLabel))
            .addGap(14, 14, 14)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(noteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(noteLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(commentaireLabel)
                .addComponent(commentaireTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(ReponseLabel)
                .addComponent(RepTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap())
    );

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addGap(20, 20, 20)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 328, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(0, 20, Short.MAX_VALUE))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addGap(20, 20, 20)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGap(18, 18, 18)
            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
    );

    add(jPanel1, "card2");
}// </editor-fold>//GEN-END:initComponents

    private void StatistiquesBouttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StatistiquesBouttonActionPerformed

        int size = tablemesEvaluation.getRowCount();

        List<Double> notes = new ArrayList<Double>();
        List<Integer> ids = new ArrayList<Integer>();
        List<String> noms = new ArrayList<String>();
        EvaluationDAO evaluationDAO = new EvaluationDAO();
        System.out.println("ouh ouh  " + size);
        //System.out.println(evaluationDAO.getMoyenneByAdherent(8));
        int idadh;
        float ess;
        for (int i = 0; i < size; i++) {

            System.out.println(tablemesEvaluation.getValueAt(i, 4).toString());
            idadh = Integer.parseInt(tablemesEvaluation.getValueAt(i, 1).toString());
            String nom = (tablemesEvaluation.getValueAt(i, 2).toString());
            // notes.add((new Double (tablemesEvaluation.getValueAt(i,2).toString())));
            System.out.println(" id adherent " + idadh);
            // System.out.println("moyenne "+);
            ess = evaluationDAO.getMoyenneByAdherent(idadh);
            System.out.println(ess);
            // notes.add((new Double (evaluationDAO.getMoyenneByAdherent((int) tablemesEvaluation.getValueAt(i,1)))));
            notes.add((new Double(ess)));
            ids.add((int) tablemesEvaluation.getValueAt(i, 1));
            noms.add(nom);

        }

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (int i = 0; i < size; i++) {

            dataset.setValue(new Double(notes.get(i)), "notes", new String(noms.get(i)));

        }

        //dataset.setValue(evaluationTable);

        JFreeChart chart = ChartFactory.createBarChart3D("Notes Adhrents", "Noms des adhrents", "Notes",
                dataset, PlotOrientation.VERTICAL, true, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.black);
        ChartFrame frame = new ChartFrame(" les notes des adhrents", chart);
        frame.setVisible(true);
        frame.setSize(700, 800);
        ValueMarker marker = new ValueMarker(15);
        marker.setLabel(" seuil de l'valuation ");
        marker.setLabelAnchor(RectangleAnchor.CENTER);
        marker.setPaint(Color.YELLOW);
        p.addRangeMarker(marker);
        p.setRangeGridlinePaint(Color.RED);

        try {

        }

        catch (Exception e) {
        }

        /*
        String note =noteTxt.getText();
        String idAdherent=idAdherentEvaluText.getText();
            
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.setValue(new Double(note), "notes", new Double(idAdherent));
        //dataset.setValue(evaluationTable);
            
        JFreeChart chart = ChartFactory.createBarChart3D("Notes Adhrents", "Id Adhrents", "Notes", dataset, PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p= chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.black);
        ChartFrame frame = new ChartFrame(" les notes des adhrents", chart);
        frame.setVisible(true);
        frame.setSize(450,350);
        */
        try {

            final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
            final File file1 = new File("statistiques.png");
            ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        }

        catch (Exception e) {
        }
    }//GEN-LAST:event_StatistiquesBouttonActionPerformed

private void tablemesEvaluationMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablemesEvaluationMouseClicked
    try {

        int row =tablemesEvaluation.getSelectedRow();
        String Table_Click = (tablemesEvaluation.getModel().getValueAt(row, 0).toString());
        String requete ="select * from evaluation where id_evaluation='"+Table_Click+"'";

        Statement statement = MyConnection.getInstance().createStatement();
        PreparedStatement ps = MyConnection.getInstance().prepareStatement(requete);
        ResultSet resultat = ps.executeQuery();

        if (resultat.next())
        {

            String add1 =resultat.getString("id_evaluation");
            idEvaluationText.setText(add1);

            String add2 =""+resultat.getInt(2);

            idAdherentEvaluText.setText(add2);
            String add3 =resultat.getString("id_evaluateur");
            idEvaluateurText.setText(add3);
            String add4 =resultat.getString("note");
            noteTxt.setText(add4);
            String add5 =resultat.getString("commentaire");
            commentaireTxt.setText(add5);
            String add6 =resultat.getString("reponse");
            RepTxt.setText(add6);

        }

    }

    catch (Exception e )
    {

        JOptionPane.showMessageDialog(null, e);
    }

}//GEN-LAST:event_tablemesEvaluationMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField RepTxt;
    private javax.swing.JLabel ReponseLabel;
    private javax.swing.JButton StatistiquesBoutton;
    private javax.swing.JLabel commentaireLabel;
    private javax.swing.JTextField commentaireTxt;
private javax.swing.JTextField idAdherentEvaluText;
    private javax.swing.JLabel idAdherentevalueLabel;
    private javax.swing.JLabel idEvaluateurLabel;
    private javax.swing.JTextField idEvaluateurText;
    private javax.swing.JLabel idEvaluationLabel;
    private javax.swing.JTextField idEvaluationText;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel noteLabel;
    private javax.swing.JTextField noteTxt;
    private javax.swing.JTable tablemesEvaluation;
    // End of variables declaration//GEN-END:variables
}