Erreur [Résolu/Fermé]

Signaler
Messages postés
18
Date d'inscription
jeudi 17 mars 2016
Statut
Membre
Dernière intervention
29 octobre 2016
-
Messages postés
18
Date d'inscription
jeudi 17 mars 2016
Statut
Membre
Dernière intervention
29 octobre 2016
-
svp si vous pouvez m aider sur ce code j arrive pas ale compiler ni a corriger les erreurs qu'il m affiche:

package gestagiaires;
import java.sql.*;
import javax.swing.JOptionPane;


public class start extends javax.swing.JFrame {
int s;

stagiaire stg = new stagiaire();
String d; int mat;
double m;
    private Object dtgrid;
    private final Object grp;
    
    /** Creates new form start */
    public start() {
        initComponents();
        grp.add(jRadioButton1);
         grp.add(jRadioButton2);
    }
public void afficher(){
  dtgrid.setModel(stg.gettruks());
}

 public void viderboxes(){
     jTextField1.setText("");
     jTextField2.setText("");
     jTextField3.setText("");
     jTextField4.setText("");
     jTextField5.setText("");
 
 }
    /** 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">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        scrollPane1 = new java.awt.ScrollPane();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jTextField6 = new javax.swing.JTextField();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("matricule:");

        jLabel2.setText("nom:");

        jLabel3.setText("prenom:");

        jLabel4.setText("moyenne:");

        jLabel5.setText("date:");

        jLabel6.setBackground(new java.awt.Color(255, 204, 255));
        jLabel6.setText("gestion des stagiaires");

        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });

        jTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField3ActionPerformed(evt);
            }
        });

        jTextField4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField4ActionPerformed(evt);
            }
        });

        jTextField5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField5ActionPerformed(evt);
            }
        });

        jButton1.setText("ajouter");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("modifier");

        jButton3.setText("supprimer");

        jButton4.setText("rechercher");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("afficher");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jRadioButton1.setText("par nom");

        jRadioButton2.setText("par Mat");
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(19, 19, 19)
                                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(50, 50, 50)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(15, 15, 15)))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                            .addComponent(jTextField4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                            .addComponent(jTextField5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE))
                        .addGap(50, 50, 50)
                        .addComponent(scrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 459, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addComponent(jButton5)
                        .addGap(26, 26, 26)
                        .addComponent(jButton1)
                        .addGap(33, 33, 33)
                        .addComponent(jButton2)
                        .addGap(35, 35, 35)
                        .addComponent(jButton3)
                        .addGap(39, 39, 39)
                        .addComponent(jButton4)
                        .addGap(33, 33, 33)
                        .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jRadioButton2, 0, 0, Short.MAX_VALUE)
                            .addComponent(jRadioButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 73, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(scrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jLabel6)
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(19, 19, 19)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton5)
                            .addComponent(jButton1)
                            .addComponent(jButton2)
                            .addComponent(jButton3)
                            .addComponent(jButton4)
                            .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(38, 38, 38))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jRadioButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRadioButton2)
                        .addContainerGap())))
        );

        jButton5.getAccessibleContext().setAccessibleName("");

        pack();
    }// </editor-fold>                        

private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {                                            
m = Double.valueOf(jTextField4.getText());
  d= jTextField5.getText();
  stg.ajouter(jTextField2.getText(),jTextField3.getText(),m,d);
  afficher();
}                                           
                                 

private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {                                            
m = Double.valueOf(jTextField4.getText());
   mat = Integer.valueOf(jTextField1.getText());
   stg.modifier(mat,jTextField2.getText(),jTextField3.getText(),m,jTextField5.getText());
   afficher();
}                                           

private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {                                            
 mat = Integer.valueOf(jTextField1.getText());
    stg.supprimer(mat);
    afficher();
}                                           

private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {                                            
viderboxes();
      try {
     
       if (jRadioButton1.isSelected()){
       stg.rset = stg.recherchenom(jTextField6.getText());
       }else if (jRadioButton1.isSelected()){
       mat = Integer.valueOf(jTextField6.getText());
       stg.rset = stg.recherchemat(mat);
       }    
       if (stg.rset.getRow()<=0){
               JOptionPane.showMessageDialog(null, " Stagiaire n'exist pas ", "X--ERROR", JOptionPane.ERROR_MESSAGE);
       }else{
            jTextField1.setText(stg.rset.getString(1));
            jTextField2.setText(stg.rset.getString(2));
            jTextField3.setText(stg.rset.getString(3));
            jTextField4.setText(stg.rset.getString(4).substring(0, 3));
            jTextField5.setText(stg.rset.getString(5));
      
       }
        } catch (SQLException ex) {
           
}
}                                           

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
afficher();
}                                        

private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                              
afficher();
}                                             

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
// TODO add your handling code here:
}                                        

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
// TODO add your handling code here:
}                                        
 private void dtgridMouseClicked(java.awt.event.MouseEvent evt) {                                    
try {
    s = dtgrid.getSelectedRow();
    
}catch(Exception e){

}
}                                   

private void formWindowClosed(java.awt.event.WindowEvent evt) {                                  
mybd.disconnect();
}                                 

private void txtbox1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
// TODO add your handling code here:
}                                       

private void searchboxActionPerformed(java.awt.event.ActionEvent evt) {                                          
// TODO add your handling code here:
}                                         

private void txtbox4ActionPerformed(java.awt.event.ActionEvent evt) {                                        
// TODO add your handling code here:
}                                       
    /**


* @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(start.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(start.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(start.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(start.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new start().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private java.awt.ScrollPane scrollPane1;
    // End of variables declaration

1 réponse

Messages postés
16372
Date d'inscription
samedi 31 mai 2008
Statut
Modérateur
Dernière intervention
23 juillet 2021
2 858
Bonjour,

1)
    private Object dtgrid;
    private final Object grp;
    
    /** Creates new form start */
    public start() {
        initComponents();
        grp.add(jRadioButton1);
         grp.add(jRadioButton2);
    }
public void afficher(){
  dtgrid.setModel(stg.gettruks());
}

grp
ne devrait pas être de type Object, vu son utilisation c'est un java.awt.Container. De plus comme il est déclaré final il doit obligatoirement être instancié par le constructeur.

Idem pour dtgrid, ce n'est pas un Object mais un javax.swing.JTable

2)
private void formWindowClosed(java.awt.event.WindowEvent evt) {                                  
mybd.disconnect();
}

Tu dois déclarer et initialiser un attribut mybd si tu veux l'utiliser. Sinon il faut supprimer son utilisation.

3) Remarque : ton code dépend de la classe stagiaire, si elle est mal faite cela peut entraîner des erreurs de compilation supplémentaire.

Voici le minimum à avoir pour compiler la classe start :
public class stagiaire {
    public ResultSet rset;
    public TableModel gettruks() {
        return null;
    }
    public void ajouter(String text, String text2, double m, String d) {
    }
    public void modifier(int mat, String text, String text2, double m, String text3) {        
    }
    public void supprimer(int mat) {        
    }
    public ResultSet recherchenom(String text) {
        return null;
    }
    public ResultSet recherchemat(int mat) {
        return null;
    }
}
Messages postés
18
Date d'inscription
jeudi 17 mars 2016
Statut
Membre
Dernière intervention
29 octobre 2016

mercii pour votre reponse voila ma classe stagiaire je crois pas y a un probleme mais le probleme dans l autre classe j ai bien saisi ce que vous avez di mais je sais pa encore qu est ce que je dois modifier et enlever

package gestagiaires;


import java.sql.*;
import javax.swing.table.*;
import javax.swing.JOptionPane;

public class stagiaire {
public Statement stx;
public String query;
public ResultSet rset;

public Connection cn;
JOptionPane jop1, jop2, jop3;
public stagiaire(){
mybd.connect();
cn = mybd.getConn();
}
public void ajouter(String nom,String prenom,double moy,String date){
try {
query="INSERT INTO stg VALUES ('"+nom+"', '"+prenom+"', "+moy+", '"+date+"')";
stx = cn.createStatement();
int rs = stx.executeUpdate(query); cn.commit();

} catch (SQLException ex) {

}

}
public void modifier(int mat,String nom,String prenom,double moy,String date){
try {
query="UPDATE stg SET nom='"+nom+"',prenom='"+prenom+"',moyenne="+moy+",daten='"+date+"' WHERE mat="+mat+"";
stx = cn.createStatement();
int rs = stx.executeUpdate(query); cn.commit();

} catch (SQLException ex) {

}
}
public void supprimer(int mat){
try {


query="DELETE FROM stg WHERE mat = "+mat+"";
stx = cn.createStatement();
int rs = stx.executeUpdate(query);
cn.commit();

}catch (SQLException ex) {
}


}
public ResultSet recherchemat(int mat){

try {
//Execution de la requete
query="SELECT * FROM stg WHERE mat = "+mat+"";
stx = cn.createStatement();
rset = stx.executeQuery(query); cn.commit();
rset.next();
} catch (SQLException ex) {

}
return rset;
}
public DefaultTableModel gettruks(){
DefaultTableModel dt = new DefaultTableModel();
dt.addColumn("Mat");
dt.addColumn("Nom");
dt.addColumn("Prenom");
dt.addColumn("Moyenne");
dt.addColumn("Date");
try {
query="SELECT * FROM stg ";
stx = cn.createStatement();
rset = stx.executeQuery(query); cn.commit();
while(rset.next()){
Object [] st = {rset.getInt(1),rset.getString(2),rset.getString(3),rset.getString(4),rset.getString(5)};
dt.addRow(st);
}

} catch (SQLException ex) {

}
return dt;
}

ResultSet recherchenom(String text) {
throw new UnsupportedOperationException("Not yet implemented");
}

}
Messages postés
16372
Date d'inscription
samedi 31 mai 2008
Statut
Modérateur
Dernière intervention
23 juillet 2021
2 858
"j ai bien saisi ce que vous avez di mais je sais pa encore qu est ce que je dois modifier et enlever"
Si tu as compris ce que j'ai dit où est la difficulté à trouver comment modifier ?
Je t'ai tout indiqué !!!

1) Tu remplaces ça :
    private Object dtgrid;
    private final Object grp;

Par ça :
    private JTable dtgrid;
    private final Container grp = new Container();

2) Tu ajoutes (je ne sais pas quoi, mais ça doit être dans tes classes)
    private ???? mydb;
Messages postés
18
Date d'inscription
jeudi 17 mars 2016
Statut
Membre
Dernière intervention
29 octobre 2016

aaah daccord je vois mercii beaucoup je vais tout de suite essayer