Gui.admin.GererlesSratistique.java Source code

Java tutorial

Introduction

Here is the source code for Gui.admin.GererlesSratistique.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.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.data.category.DefaultCategoryDataset;

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

    /**
     * Creates new form GererlesSratistique
     */
    public GererlesSratistique() {
        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() {

    jScrollPane4 = new javax.swing.JScrollPane();
    evaluationTable = new javax.swing.JTable();
    idEvaluationLabel = new javax.swing.JLabel();
    idAdherentevalueLabel = new javax.swing.JLabel();
    idEvaluateurLabel = new javax.swing.JLabel();
    noteLabel = new javax.swing.JLabel();
    commentaireLabel = new javax.swing.JLabel();
    ReponseLabel = new javax.swing.JLabel();
    idEvaluationText = new javax.swing.JTextField();
    idAdherentEvaluText = new javax.swing.JTextField();
    idEvaluateurText = new javax.swing.JTextField();
    noteTxt = new javax.swing.JTextField();
    commentaireTxt = new javax.swing.JTextField();
    RepTxt = new javax.swing.JTextField();
    StatistiquesBoutton = new javax.swing.JButton();

    evaluationTable.setModel(new EvaluationTable()
    );
    evaluationTable.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            evaluationTableMouseClicked(evt);
        }
    });
    jScrollPane4.setViewportView(evaluationTable);

    idEvaluationLabel.setText("id evaluation");

    idAdherentevalueLabel.setText("id adhrent evalu");

    idEvaluateurLabel.setText("id evaluateur");

    noteLabel.setText("note");

    commentaireLabel.setText("commentaire");

    ReponseLabel.setText("Rponse");

    StatistiquesBoutton.setText("gnrer Statistique");
    StatistiquesBoutton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            StatistiquesBouttonActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(72, 72, 72)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(idEvaluationLabel)
                        .addComponent(idAdherentevalueLabel)
                        .addComponent(idEvaluateurLabel)
                        .addComponent(noteLabel)
                        .addComponent(commentaireLabel)
                        .addComponent(ReponseLabel))
                    .addGap(37, 37, 37)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(idEvaluationText, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                        .addComponent(idAdherentEvaluText)
                        .addComponent(idEvaluateurText)
                        .addComponent(noteTxt)
                        .addComponent(commentaireTxt)
                        .addComponent(RepTxt)))
                .addGroup(layout.createSequentialGroup()
                    .addGap(130, 130, 130)
                    .addComponent(StatistiquesBoutton)))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(22, 22, 22)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(idEvaluationLabel)
                                .addComponent(idEvaluationText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(26, 26, 26)
                            .addGroup(layout.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(27, 27, 27)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(idEvaluateurLabel)
                                .addComponent(idEvaluateurText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(25, 25, 25)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(noteLabel)
                                .addComponent(noteTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(34, 34, 34)
                            .addComponent(commentaireLabel))
                        .addComponent(commentaireTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(27, 27, 27)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ReponseLabel)
                        .addComponent(RepTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(44, 44, 44)
                    .addComponent(StatistiquesBoutton))
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
}// </editor-fold>//GEN-END:initComponents

private void evaluationTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_evaluationTableMouseClicked

    try {

        int row =evaluationTable.getSelectedRow();
        String Table_Click = (evaluationTable.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.getString("id_adherentEvalu");
            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_evaluationTableMouseClicked

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

        int size = evaluationTable.getRowCount();
        System.out.println(size);
        List<Double> notes = new ArrayList<Double>();
        List<Integer> ids = new ArrayList<Integer>();

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

            notes.add((new Double(evaluationTable.getValueAt(i, 3).toString())));

            ids.add((int) evaluationTable.getValueAt(i, 1));

        }

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

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

        }

        //dataset.setValue(evaluationTable);

        JFreeChart chart = ChartFactory.createBarChart3D("Notes Adhrents", "Id 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(450, 350);

        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

    // 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.JTable evaluationTable;
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.JScrollPane jScrollPane4;
    private javax.swing.JLabel noteLabel;
    private javax.swing.JTextField noteTxt;
    // End of variables declaration//GEN-END:variables
}