Ajouter un commentaire

zineb2206_9777

Salut

Merci nasix et voila le code de toute la classe

chargerTableauvaleur() c'est la methode qui charge tout les champs de la table grace a la methode getListevaleur qui se trouve dans une autre classe et c'est valeurservices

public class Valeur extends javax.swing.JFrame {

    Vector vdata = null;

    private void chargerTableauvaleur() {
        vdata = valeurservices.getListevaleur();
        Vector vcolonnename = (Vector) vdata.elementAt(0);
        vdata.removeElementAt(0);
        tablegroupe.setModel(new DefaultTableModel(vdata, vcolonnename));

    }

chargerTableau() c'est la methode qui charge les information demander via la methode getlistevaleur qui se trouve dans cette classe parcque j'ai besoin de deux boutton,un qui affiche toute la table et un autre pour afficher selon la date demander

private void chargerTableau() {
        Date d = new Date(jTextField1.getText());
        System.out.println(d);
        vdata = getListevaleur(d);
        Vector vcolonnename = (Vector) vdata.elementAt(0);
        vdata.removeElementAt(0);
        tablegroupe.setModel(new DefaultTableModel(vdata, vcolonnename));

    }
 public Valeur() {
        initComponents();
    }



boutton qui affiche toute la table

 // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btnsupprimer = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablegroupe = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                chargement(evt);
            }
        });

        btnsupprimer.setText("Afficher toutes les informations");
        btnsupprimer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnsupprimerbtaffichage(evt);
            }
        });

        jScrollPane1.setViewportView(tablegroupe);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addGap(24, 24, 24))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(66, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(145, 145, 145)
                        .addComponent(btnsupprimer, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnsupprimer)
                .addGap(36, 36, 36)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45))
        );

        jButton1.setText("Accueil");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                retour(evt);
            }
        });

        jButton2.setText("Fermer");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Fermer(evt);
            }
        });

        jButton3.setText("test");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });

        jTextField1.setText("jTextField1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 491, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 308, Short.MAX_VALUE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 303, Short.MAX_VALUE)
                        .addComponent(jButton2)))
                .addGap(51, 51, 51))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        
    private void btnsupprimerbtaffichage(java.awt.event.MouseEvent evt) {                                         
        // TODO add your handling code here:

        chargerTableauvaleur();

       
       
    }       

un bouton de retour a la page precedente

 private void retour(java.awt.event.MouseEvent evt) {                        
        // TODO add your handling code here:
        JFrame j = new accueil();
        j.setVisible(true);
    }     

boutton qui ferme la fenetre

  private void Fermer(java.awt.event.MouseEvent evt) {                        
        // TODO add your handling code here:
        this.setVisible(true);
        System.exit(0);
    }  

la methode getlistevaleur pour l'ffichage par date
   public static Vector getListevaleur(Date d) {


        Vector vdata = new Vector();
        ResultSet rs = null;
        try {
            Connection conn = BDConnection.connecter();

            Statement stmt = null;
            try {
                stmt = (Statement) conn.createStatement();
                rs = stmt.executeQuery("select *  from Valeur where date='" + d + "' ");
                ResultSetMetaData rsmd = rs.getMetaData();
                int colonneccount = rsmd.getColumnCount();
                Vector vcolonnename = new Vector();
                for (int i = 1; i <= colonneccount; i++) {
                    vcolonnename.addElement(rsmd.getColumnName(i));
                }
                vdata.addElement(vcolonnename);
                Vector vligne;
                while (rs.next()) {
                    //System.out.println(rs.getString("d"));

                    vligne = new Vector();
                    for (int i = 1; i <= colonneccount; i++) {
                        vligne.addElement(rs.getObject(i));
                    }
                    vdata.addElement(vligne);
                }
            } finally {
                rs.close();
                stmt.close();
                BDConnection.deconnecter();
            }
        } catch (Exception e) {
        }
        return vdata;
    }


et en fin le fameux boutton d'affichage par date
  private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:

        // Date d = new Date(jTextField1.getText());
        // getListevaleur(d);
        chargerTableau();
    // chargerid();
    }                                     

 public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Valeur().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton btnsupprimer;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTable tablegroupe;
    // End of variables declaration
}

merci pour l'aide

Filtered HTML

Plain text

CAPTCHA
Cette question permet de vérifier que vous n'êtes pas un robot spammeur :-)
 Y   Y   SSS   W     W  PPPP   EEEE 
Y Y S W W P P E
Y SSS W W W PPPP EEE
Y S W W W P E
Y SSSS W W P EEEE