com.ftt.gui.FrameFormation.java Source code

Java tutorial

Introduction

Here is the source code for com.ftt.gui.FrameFormation.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 com.ftt.gui;

import com.ftt.dao.classes.FormationDAO;
import com.ftt.entities.Formation;
import java.awt.Font;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.util.List;

/**
 *
 * @author kais
 */
public class FrameFormation extends javax.swing.JFrame {

    int id;
    ///////////////////////////

    private void loadAllFormation() {
        FormationDAO fd = new FormationDAO();
        ArrayList<Formation> formations = (ArrayList<Formation>) fd.select();
        int nbLigne = formations.size();
        tableformation.setModel(new javax.swing.table.DefaultTableModel(new Object[nbLigne][], new String[] { "id",
                "nom", "desciption", "lieux", "date d'ouverture", "date de cloture", "cible" }));

        Integer ii = 0;
        for (int i = 0; i < formations.size(); i++) {
            Integer id2 = formations.get(i).getId();
            String nom = formations.get(i).getNom();
            String description = formations.get(i).getDescription();
            String lieu = formations.get(i).getLieux();
            String dateouv = formations.get(i).getDateOuverture();
            String dateclo = formations.get(i).getDateCloture();
            String cible = formations.get(i).getCible();

            tableformation.setValueAt(id2, ii, 0);
            tableformation.setValueAt(nom, ii, 1);
            tableformation.setValueAt(description, ii, 2);
            tableformation.setValueAt(lieu, ii, 3);
            tableformation.setValueAt(dateouv, ii, 4);
            tableformation.setValueAt(dateclo, ii, 5);
            tableformation.setValueAt(cible, ii, 6);
            ii++;
        }
        TableColumn idClmn = tableformation.getColumn("id");
        idClmn.setMaxWidth(0);
        idClmn.setMinWidth(0);
        idClmn.setPreferredWidth(0);
    }

    public FrameFormation() {
        setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
        initComponents();
        loadAllFormation();
    }

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

        jLabel5 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        lieux = new javax.swing.JTextField();
        combocible = new javax.swing.JComboBox();
        ajouter = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        categorie = new javax.swing.JComboBox();
        supprimer2 = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        tableformation = new javax.swing.JTable();
        modifier = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        search = new javax.swing.JTextField();
        dateov = new com.toedter.calendar.JDateChooser();
        dateclot = new com.toedter.calendar.JDateChooser();
        pdf1 = new javax.swing.JButton();
        pdf2 = new javax.swing.JButton();
        Retour = new javax.swing.JButton();
        descriptionf = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        nomf = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabel5.setBackground(new java.awt.Color(0, 102, 51));
        jLabel5.setFont(new java.awt.Font("Bookman Old Style", 1, 24)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(255, 255, 0));
        jLabel5.setText("Gestion des formations");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(40, 140, 300, 50);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Nom*");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(20, 240, 60, 15);

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(255, 255, 255));
        jLabel7.setText("Date d'ouverture*");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(20, 390, 113, 15);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(255, 255, 255));
        jLabel8.setText("Date de cloture*");
        getContentPane().add(jLabel8);
        jLabel8.setBounds(20, 440, 110, 15);

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel9.setForeground(new java.awt.Color(255, 255, 255));
        jLabel9.setText("Cible*");
        getContentPane().add(jLabel9);
        jLabel9.setBounds(20, 490, 40, 15);

        lieux.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lieuxActionPerformed(evt);
            }
        });
        getContentPane().add(lieux);
        lieux.setBounds(140, 330, 210, 30);

        combocible.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Joueur", "Arbitre" }));
        combocible.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                combocibleActionPerformed(evt);
            }
        });
        getContentPane().add(combocible);
        combocible.setBounds(140, 480, 210, 30);

        ajouter.setBackground(new java.awt.Color(204, 204, 255));
        ajouter.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        ajouter.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/com/ftt/gestionUtilisateurs/images/add.png"))); // NOI18N
        ajouter.setText("AJOUTER");
        ajouter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ajouterActionPerformed(evt);
            }
        });
        getContentPane().add(ajouter);
        ajouter.setBounds(210, 540, 140, 40);

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel10.setForeground(new java.awt.Color(255, 255, 255));
        jLabel10.setText("Catgorie:");
        getContentPane().add(jLabel10);
        jLabel10.setBounds(570, 230, 63, 15);

        categorie.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "lieux" }));
        categorie.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                categorieActionPerformed(evt);
            }
        });
        getContentPane().add(categorie);
        categorie.setBounds(650, 220, 80, 30);

        supprimer2.setBackground(new java.awt.Color(204, 204, 255));
        supprimer2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        supprimer2.setIcon(new javax.swing.ImageIcon(
                getClass().getResource("/com/ftt/gestionUtilisateurs/images/delete.png"))); // NOI18N
        supprimer2.setText("SUPPRIMER");
        supprimer2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                supprimer2ActionPerformed(evt);
            }
        });
        getContentPane().add(supprimer2);
        supprimer2.setBounds(520, 540, 130, 40);

        tableformation.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] {

        }));
        tableformation.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableformationMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(tableformation);

        getContentPane().add(jScrollPane4);
        jScrollPane4.setBounds(390, 300, 860, 215);

        modifier.setBackground(new java.awt.Color(204, 204, 255));
        modifier.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        modifier.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/com/ftt/gestionUtilisateurs/images/edit.png"))); // NOI18N
        modifier.setText("MODIFIER");
        modifier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modifierActionPerformed(evt);
            }
        });
        getContentPane().add(modifier);
        modifier.setBounds(390, 540, 120, 40);

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel11.setForeground(new java.awt.Color(255, 255, 255));
        jLabel11.setText("Liste des formations");
        getContentPane().add(jLabel11);
        jLabel11.setBounds(383, 270, 130, 15);

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel12.setForeground(new java.awt.Color(255, 255, 255));
        jLabel12.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/com/ftt/gestionUtilisateurs/images/find.png"))); // NOI18N
        jLabel12.setText("Rechercher formation :");
        getContentPane().add(jLabel12);
        jLabel12.setBounds(383, 232, 170, 16);

        search.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchActionPerformed(evt);
            }
        });
        search.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                searchKeyReleased(evt);
            }
        });
        getContentPane().add(search);
        search.setBounds(740, 220, 180, 30);
        getContentPane().add(dateov);
        dateov.setBounds(140, 380, 210, 30);
        getContentPane().add(dateclot);
        dateclot.setBounds(140, 430, 210, 30);

        pdf1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        pdf1.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/com/ftt/gestionUtilisateurs/images/PDF.png"))); // NOI18N
        pdf1.setText("EXPORTER");
        pdf1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pdf1ActionPerformed(evt);
            }
        });
        getContentPane().add(pdf1);
        pdf1.setBounds(75, 540, 125, 40);

        pdf2.setBackground(new java.awt.Color(204, 204, 255));
        pdf2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        pdf2.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/com/ftt/gestionUtilisateurs/images/PDF.png"))); // NOI18N
        pdf2.setText("Expoter la table en PDF");
        pdf2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pdf2ActionPerformed(evt);
            }
        });
        getContentPane().add(pdf2);
        pdf2.setBounds(660, 540, 230, 40);

        Retour.setBackground(new java.awt.Color(204, 204, 255));
        Retour.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        Retour.setIcon(new javax.swing.ImageIcon(
                getClass().getResource("/com/ftt/gestionUtilisateurs/images/back-icon.png"))); // NOI18N
        Retour.setText("Retour");
        Retour.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RetourActionPerformed(evt);
            }
        });
        getContentPane().add(Retour);
        Retour.setBounds(50, 650, 110, 40);
        getContentPane().add(descriptionf);
        descriptionf.setBounds(140, 280, 210, 30);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Lieux*");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(20, 340, 60, 15);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("Description*");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(20, 290, 80, 15);
        getContentPane().add(nomf);
        nomf.setBounds(140, 230, 210, 30);

        jPanel1.setBackground(new java.awt.Color(0, 51, 51));
        jPanel1.setLayout(null);

        jLabel13.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/com/ftt/gestionUtilisateurs/images/ftt.png"))); // NOI18N
        jPanel1.add(jLabel13);
        jLabel13.setBounds(43, 11, 112, 90);

        jLabel14.setBackground(new java.awt.Color(255, 255, 255));
        jLabel14.setFont(new java.awt.Font("Century Gothic", 1, 24)); // NOI18N
        jLabel14.setForeground(new java.awt.Color(255, 255, 255));
        jLabel14.setText("Fdration Tunisienne de Tennis");
        jPanel1.add(jLabel14);
        jLabel14.setBounds(540, 30, 399, 70);

        jLabel15.setIcon(new javax.swing.ImageIcon(
                getClass().getResource("/com/ftt/gestionUtilisateurs/images/1459108913_Flag_of_Tunisia.png"))); // NOI18N
        jPanel1.add(jLabel15);
        jLabel15.setBounds(1230, 0, 128, 123);

        jLabel16.setBackground(new java.awt.Color(0, 51, 51));
        jLabel16.setFont(new java.awt.Font("Century Gothic", 1, 12)); // NOI18N
        jLabel16.setForeground(new java.awt.Color(255, 255, 255));
        jLabel16.setToolTipText("");
        jLabel16.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        jLabel16.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jPanel1.add(jLabel16);
        jLabel16.setBounds(360, 80, 220, 30);

        getContentPane().add(jPanel1);
        jPanel1.setBounds(0, 0, 1390, 130);

        jLabel17.setIcon(new javax.swing.ImageIcon(
                getClass().getResource("/com/ftt/gestionUtilisateurs/images/tennis-home3.jpg"))); // NOI18N
        getContentPane().add(jLabel17);
        jLabel17.setBounds(0, 130, 1390, 610);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void combocibleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combocibleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_combocibleActionPerformed
    /////////////////

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

        Formation formation = new Formation();
        if (nomf.getText() == null || descriptionf.getText() == null || "".equals(lieux.getText())
                || dateclot.getDate() == null || dateov.getDate() == null) {
            JOptionPane.showMessageDialog(this, "Vrifier les champs !");
        } else {
            formation.setNom(nomf.getText());
            formation.setDescription(descriptionf.getText());
            formation.setLieux(lieux.getText());
            SimpleDateFormat formateur = new SimpleDateFormat("yyyy-MM-dd");
            String dateo = formateur.format(dateov.getDate());
            String datec = formateur.format(dateclot.getDate());
            formation.setDateOuverture(dateo);
            formation.setDateCloture(datec);
            formation.setCible(combocible.getSelectedItem().toString());
            FormationDAO fd = new FormationDAO();
            fd.add(formation);
            JOptionPane.showMessageDialog(this, "Formation ajout");
            loadAllFormation();
        }

    }//GEN-LAST:event_ajouterActionPerformed

    private void categorieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_categorieActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_categorieActionPerformed

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

        FormationDAO fd = new FormationDAO();
        fd.remove(id);
        JOptionPane.showMessageDialog(this, "formation supprim");
        loadAllFormation();
    }//GEN-LAST:event_supprimer2ActionPerformed
    ////////////////////

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

        DefaultTableModel model = (DefaultTableModel) tableformation.getModel();
        id = Integer.parseInt(model.getValueAt(tableformation.getSelectedRow(), 0).toString());
        nomf.setText(model.getValueAt(tableformation.getSelectedRow(), 1).toString());
        descriptionf.setText(model.getValueAt(tableformation.getSelectedRow(), 2).toString());
        lieux.setText(model.getValueAt(tableformation.getSelectedRow(), 3).toString());

    }//GEN-LAST:event_tableformationMouseClicked
    ////////////////////

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

        Formation formation = new Formation();
        FormationDAO fd = new FormationDAO();
        if (nomf.getText() == null || descriptionf.getText() == null || "".equals(lieux.getText())
                || dateclot.getDate() == null || dateov.getDate() == null) {
            JOptionPane.showMessageDialog(this, "Vrifier les champs !");
        } else {
            formation.setNom(nomf.getText());
            formation.setDescription(descriptionf.getText());
            formation.setLieux(lieux.getText());
            SimpleDateFormat formateur = new SimpleDateFormat("yyyy-MM-dd");
            String dateo = formateur.format(dateov.getDate());
            String datec = formateur.format(dateclot.getDate());
            formation.setDateOuverture(dateo);
            formation.setDateCloture(datec);
            formation.setCible(combocible.getSelectedItem().toString());
            formation.setId(id);
            fd.update(formation);
            JOptionPane.showMessageDialog(this, "Formation modifi");
            loadAllFormation();
        }
    }//GEN-LAST:event_modifierActionPerformed

    private void searchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_searchActionPerformed

    private void lieuxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lieuxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_lieuxActionPerformed
    ////////////////

    private void searchKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchKeyReleased

        FormationDAO fd = new FormationDAO();
        String choix;
        choix = categorie.getSelectedItem().toString();
        ArrayList<Formation> formations = (ArrayList<Formation>) fd.rechercherByNom(search.getText(), choix);
        int nbLigne = formations.size();
        tableformation.setModel(new javax.swing.table.DefaultTableModel(new Object[nbLigne][], new String[] { "id",
                "nom", "desciption", "lieux", "date d'ouverture", "date de cloture", "cible" }));

        Integer ii = 0;
        for (int i = 0; i < formations.size(); i++) {
            Integer id2 = formations.get(i).getId();
            String nom = formations.get(i).getNom();
            String description = formations.get(i).getDescription();
            String lieu = formations.get(i).getLieux();
            String dateouv = formations.get(i).getDateOuverture();
            String dateclo = formations.get(i).getDateCloture();
            String cible = formations.get(i).getCible();

            tableformation.setValueAt(id2, ii, 0);
            tableformation.setValueAt(nom, ii, 1);
            tableformation.setValueAt(description, ii, 2);
            tableformation.setValueAt(lieu, ii, 3);
            tableformation.setValueAt(dateouv, ii, 4);
            tableformation.setValueAt(dateclo, ii, 5);
            tableformation.setValueAt(cible, ii, 6);
            ii++;
        }
        TableColumn idClmn = tableformation.getColumn("id");
        idClmn.setMaxWidth(0);
        idClmn.setMinWidth(0);
        idClmn.setPreferredWidth(0);
    }//GEN-LAST:event_searchKeyReleased
    //////////

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

        if (nomf.getText() == null || descriptionf.getText() == null || "".equals(lieux.getText())
                || dateclot.getDate() == null || dateov.getDate() == null) {
            JOptionPane.showMessageDialog(this, "Vrifier les champs !");
        } else {
            SimpleDateFormat formateur = new SimpleDateFormat("dd-MM-yyyy");
            String val1 = lieux.getText();
            String val2 = formateur.format(dateov.getDate());
            String val3 = formateur.format(dateclot.getDate());
            String val4 = combocible.getSelectedItem().toString();
            String val5 = nomf.getText();
            String val6 = descriptionf.getText();
            Document document = new Document();

            try {
                PdfWriter.getInstance(document, new FileOutputStream("rapport.pdf"));

                document.open();

                com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("ftt.png");
                document.add(image);
                document.add(new Paragraph("Liste des formations",
                        FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD)));
                document.add(new Paragraph(formateur.format(new Date())));
                String val322 = formateur.format(new Date());
                document.add(new Paragraph("                    "));

                PdfPTable table = new PdfPTable(2);
                PdfPCell cell = new PdfPCell(new Paragraph("formations"));
                cell.setColspan(4);
                cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
                cell.setBackgroundColor(BaseColor.BLUE);
                table.addCell(cell);
                table.addCell("Nom formation");
                table.addCell(val5);
                table.addCell(cell);
                table.addCell("Description");
                table.addCell(val6);
                table.addCell(cell);
                table.addCell("Lieux");
                table.addCell(val1);
                table.addCell("Date d'ouverture");
                table.addCell(val2);
                table.addCell("Date de cloture");
                table.addCell(val3);
                table.addCell("Cible");
                table.addCell(val4);
                document.add(table);
                document.add(new Paragraph("    "));
                document.add(new Paragraph("    "));
                document.add(new Paragraph("Responsable des formations"));
                document.add(new Paragraph("Federation Tunisenne de Tennis"));
                document.close();
                JOptionPane.showMessageDialog(null, "Rapport Enregistrer");
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);
            }
        }
    }//GEN-LAST:event_pdf1ActionPerformed
    /////////////

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

        FormationDAO fd = new FormationDAO();
        ArrayList<Formation> formations = (ArrayList<Formation>) fd.select();
        SimpleDateFormat formateur = new SimpleDateFormat("dd-MM-yyyy");

        Document document = new Document();

        try {
            PdfWriter.getInstance(document, new FileOutputStream("rapport_formations.pdf"));

            document.open();

            com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("ftt.png");
            document.add(image);
            document.add(new Paragraph("Liste des formations",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD)));
            document.add(new Paragraph("   "));
            document.add(new Paragraph("    "));
            for (int i = 0; i < formations.size(); i++) {
                document.add(new Paragraph("    "));
                int val = formations.get(i).getId();
                String val1 = formations.get(i).getLieux();
                String val2 = formations.get(i).getDateOuverture();
                String val3 = formations.get(i).getDateCloture();
                String val4 = formations.get(i).getCible();
                String val5 = formations.get(i).getNom();
                String val6 = formations.get(i).getDescription();

                PdfPTable table = new PdfPTable(2);
                PdfPCell cell = new PdfPCell(new Paragraph("formation " + val));
                cell.setColspan(4);
                cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
                cell.setBackgroundColor(BaseColor.GRAY);
                table.addCell(cell);
                table.addCell("Nom formation");
                table.addCell(val5);
                table.addCell("Description");
                table.addCell(val6);
                table.addCell("Lieux");
                table.addCell(val1);
                table.addCell("Date d'ouverture");
                table.addCell(val2);
                table.addCell("Date de cloture");
                table.addCell(val3);
                table.addCell("Cible");
                table.addCell(val4);
                document.add(table);
            }

            document.add(new Paragraph("    "));
            document.add(new Paragraph("    "));
            document.add(new Paragraph("Responsable des formations"));
            document.add(new Paragraph("Federation Tunisenne de Tennis"));
            document.close();
            JOptionPane.showMessageDialog(null, "Rapport Enregistrer");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
    }//GEN-LAST:event_pdf2ActionPerformed

    private void RetourActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RetourActionPerformed
        Home fj = new Home();
        fj.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_RetourActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrameFormation.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrameFormation.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrameFormation.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrameFormation.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        }
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrameFormation().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Retour;
    private javax.swing.JButton ajouter;
    private javax.swing.JComboBox categorie;
    private javax.swing.JComboBox combocible;
    private com.toedter.calendar.JDateChooser dateclot;
    private com.toedter.calendar.JDateChooser dateov;
    private javax.swing.JTextField descriptionf;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextField lieux;
    private javax.swing.JButton modifier;
    private javax.swing.JTextField nomf;
    private javax.swing.JButton pdf1;
    private javax.swing.JButton pdf2;
    private javax.swing.JTextField search;
    private javax.swing.JButton supprimer2;
    private javax.swing.JTable tableformation;
    // End of variables declaration//GEN-END:variables
}