IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Java Discussion :

Transmission d'une valeur d'un panel à l'autre


Sujet :

Java

  1. #1
    Membre régulier Avatar de japhettchabao
    Homme Profil pro
    Développeur Java
    Inscrit en
    Septembre 2014
    Messages
    86
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : Togo

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2014
    Messages : 86
    Points : 75
    Points
    75
    Par défaut Transmission d'une valeur d'un panel à l'autre
    Bonjour, je developpe un logiciel de gestion d'établissement scolaire et j'utilise des cardlayouts .
    problème: pour modifier un élève, j'aimerais transmettre son id récupéré dans un jtable sur le panel de modification d'élève. mais patatra, que des erreurs. le panel ne vient même pas
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     
            if (jTable1.getSelectedRow() == -1) {
                JOptionPane.showMessageDialog(null, "Veuillez selectionner un utilisateur", "ERREUR", JOptionPane.ERROR_MESSAGE);
            } 
            else {
                String id = jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString();
                String nom = jTable1.getValueAt(jTable1.getSelectedRow(), 1).toString();
                editereleve.SetTextField(id,nom);
                conteneur.tomodifier();
            }
        }
    la page d'édition. bon j'ai pas encore corrigé ma requete sql, mais là n'est pas le problème
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    /*
     * 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 architecture;
    import architecture.Requete;
    import java.sql.SQLException;
    import javax.swing.JOptionPane;
     
    /**
     *
     * @author Japhet Tchabao
     */
    public class editereleve extends javax.swing.JPanel {
     
        static void SetTextField(String id, String nom) {
            name.setText(nom); 
            iden.setText(id);
        }
     
     
     
        /**
         * Creates new form inscriptioneleve
         */
        public editereleve() {
            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">                          
        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();
            jLabel7 = new javax.swing.JLabel();
            jLabel8 = new javax.swing.JLabel();
            jLabel9 = new javax.swing.JLabel();
            jLabel10 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            name = new javax.swing.JTextField();
            prenoms = new javax.swing.JTextField();
            lieu = new javax.swing.JTextField();
            provenance = new javax.swing.JTextField();
            nationnalite = new javax.swing.JTextField();
            parent = new javax.swing.JTextField();
            contact = new javax.swing.JTextField();
            jLabel11 = new javax.swing.JLabel();
            sexe = new javax.swing.JComboBox();
            classe = new javax.swing.JComboBox();
            jLabel12 = new javax.swing.JLabel();
            iden = new javax.swing.JLabel();
     
            jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
            jLabel1.setText("MODIFIER ELEVE");
     
            jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
            jLabel2.setText("NOM:");
     
            jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
            jLabel3.setText("PRENOMS:");
     
            jLabel4.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
            jLabel4.setText("DATE DE NAISSANCE:");
     
            jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
            jLabel5.setText("LIEU DE NAISSANCE:");
     
            jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
            jLabel6.setText("CLASSE:");
     
            jLabel7.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
            jLabel7.setText("ETABLISSEMENT DE PROVENANCE:");
     
            jLabel8.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
            jLabel8.setText("NATIONALITE:");
     
            jLabel9.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
            jLabel9.setText("NOM DU TUTEUR OU PARENT:");
     
            jLabel10.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
            jLabel10.setText("CONTACT DU TUTEUR OU PARENT:");
     
            jButton1.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
            jButton1.setText("INSCRIRE");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
     
            jButton2.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
            jButton2.setText("ANNULER");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });
     
            nationnalite.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    nationnaliteActionPerformed(evt);
                }
            });
     
            parent.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    parentActionPerformed(evt);
                }
            });
     
            jLabel11.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
            jLabel11.setText("SEXE:");
     
            sexe.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MASCULIN", "FEMININ", "HERMAPHRODITE" }));
            sexe.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    sexeActionPerformed(evt);
                }
            });
     
            classe.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "CI", "CP1", "CP2", "CE1", "CE2", "CM1", "CM2" }));
     
            jLabel12.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
            jLabel12.setText("ID:");
     
            iden.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
     
            iden.setText(" ");
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(79, 79, 79)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGap(47, 47, 47)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addComponent(jLabel6)
                                .addComponent(jLabel11))
                            .addGap(14, 14, 14)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(contact)
                                .addComponent(parent, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(nationnalite, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(provenance, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(sexe, 0, 376, Short.MAX_VALUE)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
                                        .addComponent(name)
                                        .addComponent(prenoms)
                                        .addComponent(lieu)
                                        .addComponent(classe, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGap(0, 0, Short.MAX_VALUE)))))
                    .addGap(85, 85, 85)
                    .addComponent(jLabel12)
                    .addGap(18, 18, 18)
                    .addComponent(iden, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(66, 66, 66))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel2)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12)
                            .addComponent(iden, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel3)
                        .addComponent(prenoms, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addComponent(jLabel4)
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel5)
                        .addComponent(lieu, 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.LEADING)
                        .addComponent(jLabel6)
                        .addComponent(classe, 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(jLabel7)
                        .addComponent(provenance, 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.LEADING)
                        .addComponent(jLabel8)
                        .addComponent(nationnalite, 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.LEADING)
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(parent, 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.LEADING)
                        .addComponent(jLabel10)
                        .addComponent(contact, 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.LEADING)
                        .addComponent(jLabel11)
                        .addComponent(sexe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1)
                        .addComponent(jButton2))
                    .addGap(41, 41, 41))
            );
        }// </editor-fold>                        
     
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            // TODO add your handling code here:
            String id = iden.getText();
            String no = name.getText();
            String surname = prenoms.getText();
            String lieunais = lieu.getText();
            String prove  = provenance.getText();
            String nation  = nationnalite.getText();
            String parente  = parent.getText();
            String cont  = contact.getText();
            String sex = sexe.getSelectedItem().toString();
            String claq  = classe.getSelectedItem().toString();
            String query = "UPDATE  eleves  SET nom ='"+no+"',prenoms ='"+surname+"',lieunais ='"+lieunais+"',provenance ='"+prove+"',nationalite ='"+nation+"',"
                    + "parent ='"+parente+"',contact ='"+cont+"',sexe ='"+sex+"',classe ='"+claq+"'WHERE id ='"+id+"',";
                    Requete rq = new Requete();
            try {
                rq.connexion(connexion.user, connexion.mdp);
                rq.modifier(query);
                JOptionPane.showMessageDialog(null, "Elève correctement inscrit");
                name.setText(null);
                prenoms.setText(null);
                lieu.setText(null);
                nationnalite.setText(null);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }                                        
     
        private void parentActionPerformed(java.awt.event.ActionEvent evt) {                                       
            // TODO add your handling code here:
        }                                      
     
        private void sexeActionPerformed(java.awt.event.ActionEvent evt) {                                     
            // TODO add your handling code here:
        }                                    
     
        private void nationnaliteActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
        }                                            
     
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            // TODO add your handling code here:
            conteneur.toutilisateur();
        }                                        
     
     
        // Variables declaration - do not modify                     
        private static javax.swing.JComboBox classe;
        private static javax.swing.JTextField contact;
        private static javax.swing.JLabel iden;
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel10;
        private javax.swing.JLabel jLabel11;
        private javax.swing.JLabel jLabel12;
        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.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JLabel jLabel9;
        private static javax.swing.JTextField lieu;
        private static javax.swing.JTextField name;
        private static javax.swing.JTextField nationnalite;
        private static javax.swing.JTextField parent;
        private static javax.swing.JTextField prenoms;
        private static javax.swing.JTextField provenance;
        private static javax.swing.JComboBox sexe;
        // End of variables declaration                   
    }
    voici l'erreur, je code sous netbeans.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    run:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at architecture.editereleve.SetTextField(editereleve.java:19)
    	at architecture.modifiereleve.jButton2ActionPerformed(modifiereleve.java:221)
    	at architecture.modifiereleve.access$100(modifiereleve.java:19)
    	at architecture.modifiereleve$2.actionPerformed(modifiereleve.java:96)
    	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    	at java.awt.Component.processMouseEvent(Component.java:6516)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
    	at java.awt.Component.processEvent(Component.java:6281)
    	at java.awt.Container.processEvent(Container.java:2229)
    	at java.awt.Component.dispatchEventImpl(Component.java:4872)
    	at java.awt.Container.dispatchEventImpl(Container.java:2287)
    	at java.awt.Component.dispatchEvent(Component.java:4698)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    	at java.awt.Container.dispatchEventImpl(Container.java:2273)
    	at java.awt.Window.dispatchEventImpl(Window.java:2719)
    	at java.awt.Component.dispatchEvent(Component.java:4698)
    	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
    	at java.awt.EventQueue.access$200(EventQueue.java:103)
    	at java.awt.EventQueue$3.run(EventQueue.java:694)
    	at java.awt.EventQueue$3.run(EventQueue.java:692)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    	at java.awt.EventQueue$4.run(EventQueue.java:708)
    	at java.awt.EventQueue$4.run(EventQueue.java:706)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
    Je n'ai certes pas le talent de Gates ou Job mais, mon amour mon pc, me rend plus fort qu'eux

  2. #2
    Membre actif
    Homme Profil pro
    Développeur Java/JavaEE
    Inscrit en
    Août 2014
    Messages
    194
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Java/JavaEE

    Informations forums :
    Inscription : Août 2014
    Messages : 194
    Points : 290
    Points
    290
    Par défaut
    Bonjour,

    Tu es entrain d'affecter une valeur à un composant graphique Swing qui n'est pas encore instancier donc tu ne pourras pas lui affecter une valeur tant que le setVisible de cette Jframe est à "false".
    Par contre si tu essai de faire ces manipulations à un simple attribut( String, int, float, ...)qui dois être static, ceci va fonctionner correctement.
    Et donc pour une résolution momentanée à mon avis tu peux stocker ta valeur dans ta variable static et lors du lancement de ta Jframe qui contient ton jTextField tu peux lui affecter cette valeur dans le constructeur d'initialisation.

  3. #3
    Membre régulier Avatar de japhettchabao
    Homme Profil pro
    Développeur Java
    Inscrit en
    Septembre 2014
    Messages
    86
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : Togo

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2014
    Messages : 86
    Points : 75
    Points
    75
    Par défaut pas compris
    Bonsoir, excuses moi mais j'ai beau me creuser la tête, je vois pas ce que tu veux dire. Je comprends pas. Tu pourrais faire plus simple? merci
    Je n'ai certes pas le talent de Gates ou Job mais, mon amour mon pc, me rend plus fort qu'eux

  4. #4
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    Salut,

    Je soupçonne un problème d'instance versus accès static : supprime le static devant la méthode SetTextField. Il n'y a aucune raison qu'elle soit statique. Enlève tous les static devant les autres variables dans la classe editereleve. Je suppose que tu as ajouté ces static suite à des erreurs que tu as eues en essayant d'accèder à la méthode SetTextField. Le mot clef static indique que la variable est partagée entre toutes les instances de la classe, ce qui n'a jamais aucun sens avec des champs d'interface graphique (chaque instance de panel à ses propres champs) et en plus ça risque de mal fonctionner au niveau affichage. En tout cas, le fait d'avoir un accès static à la méthode, te permet de l'appeler avant d'instancier le panel : ce qui te donne donc un NullPointerException dans ce cas (puisque fait avant que name, ou iden, soit initialisée). Déjà, sans static, tu n'auras plus ce risque.

    Après avoir retiré tous ces static, tu auras peut-être d'autres erreurs, dues à la façon d'accèder à SetTextField. Dans la classe où tu accèdes à cette méthode, celle où se trouve la méthode jButton2ActionPerformed, tu dois avoir une instanciation du panel editereleve quelque part. Genre editereleve monpanel = new editerelever();. Dans la méthode jButton2ActionPerformed, tu dois pouvoir accèder à la variable monpanel, pour faire monpanel.SetTextField(...). Donc il faut que la variable soit déclarée dans un scope commun, par exemple, en variable de classe.
    L'expression "ça marche pas" ne veut rien dire. Indiquez l'erreur, et/ou les comportements attendus et obtenus, et donnez un Exemple Complet Minimal qui permet de reproduire le problème.
    La plupart des réponses à vos questions sont déjà dans les FAQs ou les Tutoriels, ou peut-être dans une autre discussion : utilisez la recherche interne.
    Des questions sur Java : consultez le Forum Java. Des questions sur l'EDI Eclipse ou la plateforme Eclipse RCP : consultez le Forum Eclipse.
    Une question correctement posée et rédigée et vous aurez plus de chances de réponses adaptées et rapides.
    N'oubliez pas de mettre vos extraits de code entre balises CODE (Voir Mode d'emploi de l'éditeur de messages).
    Nouveau sur le forum ? Consultez Les Règles du Club.

  5. #5
    Membre actif
    Homme Profil pro
    Développeur Java/JavaEE
    Inscrit en
    Août 2014
    Messages
    194
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Java/JavaEE

    Informations forums :
    Inscription : Août 2014
    Messages : 194
    Points : 290
    Points
    290
    Par défaut
    Bonjour,

    La meilleur manière de faire c'est qu'on va supposons que nous avons deux Jframes, on appuyons sur un bouton existant dans la première on va affecté une valeur à un jtextField existant dans la deuxième puis l'afficher.
    Jframe1:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    public class Frame1 extends javax.swing.JFrame {
    private javax.swing.JButton jButton1;
    ...
     
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            Frame2 frame2=new Frame2();
            frame2.setjTextField1("test");
            frame2.setVisible(true);
        }
    }
    Jframe2:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    public class Frame2 extends javax.swing.JFrame {
    private javax.swing.JTextField jTextField;
    ...
    public void setjTextField(String chaine) {
            this.jTextField.setText(chaine);
        }
    }
    Mais si tu auras vraiment du mal à modifier ton code je te conseil de créer une variable statique de type String si tu veux et lors du déclenchement de ton événement tu dois stocker ta valeur dans cette variable et de pouvoir l'utiliser depuis n'importe quel autres interface.

  6. #6
    Modérateur
    Avatar de MasterMbg
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2011
    Messages
    719
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Kinshasa

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2011
    Messages : 719
    Points : 1 493
    Points
    1 493
    Par défaut
    Citation Envoyé par joel.drigo Voir le message
    En tout cas, le fait d'avoir un accès static à la méthode, te permet de l'appeler avant d'instancier le panel : ce qui te donne donc un NullPointerException dans ce cas (puisque fait avant que name, ou iden, soit initialisée)
    Tout à fait d'accord avec toi. En d'autres termes, le JPanel n'est pas encore créé donc les champs graphiques contenus dans ce dernier ne le sont pas non plus. Alors quand tu appelles SetTextField(...) à l'intérieur de laquelle tu fais appelles au composants graphiques non encore créés cela ne doit te produire que NullPointerException.
    Une autre idée que je pourrait te donner serait de passer un paramètre au constructeur de ta classe editerelever et d'appeler directement à l'interieur de ce constructeur la méthode SetTextField(...) défini dans la classe editerelever.
    Classe editereleve :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    public class editereleve extends javax.swing.JPanel {
         //Constructeur 
        public editereleve(String id, String nom){
          //Appel de la méthode setTextField()...
          setTextField(id, nom); 
        }
        //Méthode setTextField(...)
        public void setTextField(String id, String nom) {
           name.setText(nom); 
           iden.setText(id);
        }
        //Suite du code...
    }
    Dans le ActionPerfomed du bouton qui appelle editereleve tu tapes :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    //.........
    editereleve monpanel = new editerelever("unId", "UnName");
    //.........
    Plus tu apprends sérieusement, plus tu te rapproches d'un savoir noble. Une chose est certaine, les difficultés ne s'écarteront de ton chemin...

    Tu es nouveau dans le développement Android, la page des COURS est là pour te faciliter la vie
    Tu peux trouver la réponse à ta question dans la FAQ
    Retrouvez mon tutoriel sur la consommation des services web SOAP
    Pense à voter positivement en appuyant sur en bas à droite de la réponse qui t'a donné une piste de solution.

  7. #7
    Membre régulier Avatar de japhettchabao
    Homme Profil pro
    Développeur Java
    Inscrit en
    Septembre 2014
    Messages
    86
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : Togo

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2014
    Messages : 86
    Points : 75
    Points
    75
    Par défaut merci, j'ai réussi
    grâce à vos conseil, j'ai procédé comme suit et sa a marché
    Au niveau du conteneur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
     public static void tomodifier(String id){
            contenu.add(new editereleve(id), "edieleve");
           pile.show(contenu, "edieleve");
       }
    Au niveau du bouton
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    String id = jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString();
                editereleve monpanel = new editereleve(id);
                conteneur.tomodifier(id);
    Au niveau d'éditer eleve
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    public class editereleve extends javax.swing.JPanel {
     
     
     
        /**
         * Creates new form inscriptioneleve
         */
        public editereleve(String id) {
            initComponents();
            System.out.println("bb");
            setTextField(id); 
        }
     
     
     
       public void setTextField(String id) {
           System.out.println("bien");
           iden.setText(id);
           System.out.println("" +id);
        }
    youpiiiiiiiiiiiiiiiiiiiiiiiii
    Je n'ai certes pas le talent de Gates ou Job mais, mon amour mon pc, me rend plus fort qu'eux

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 03/02/2009, 00h07
  2. passer une valeur d'un formulaire à un autre de page différentes
    Par ouakammathieu dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 26/12/2008, 14h05
  3. Réponses: 5
    Dernier message: 27/10/2008, 14h53
  4. transferer une valeur d'un formulaire à un autre
    Par mnssylvain dans le forum IHM
    Réponses: 1
    Dernier message: 29/05/2007, 15h34
  5. Réponses: 15
    Dernier message: 02/05/2007, 18h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo