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

AWT/Swing Java Discussion :

[Debutante] pb d'affichage d'une fenêtre


Sujet :

AWT/Swing Java

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    296
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 296
    Par défaut [Debutante] pb d'affichage d'une fenêtre
    Salut,
    Mon pb est le suivant:

    je dois ouvrir une fenêtre en cliquant sur un boutton d'une autre fenêtre, jusqu'ici tout est bon puis, ensuite,dans la nouvelle fenêtre que j'ouvre je dois avoir à ajouter un service en rempliant des champs et en cliquant sur un bouton ok qui va m'exécuter une méthode mais le pb c'est dans la nouvelle fenêtre que j'ouvre, j'arrive pas afficher mes boutons et label... bref elle est vide.

    aidez svp

    voila le code que j'ai fais:

    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
       private void AjouterSActionPerformed(java.awt.event.ActionEvent evt) {
     
    	   getContentPane().setLayout(null);
     
           jDialog1.setTitle("Ajouter un Service");
           jDialog1.setResizable(false);
           addWindowListener(new java.awt.event.WindowAdapter() {
               public void windowClosing(java.awt.event.WindowEvent evt) {
                   exitForm(evt);
               }
           });
       	jDialog1.setVisible(true);
       	 jDialog1.setSize(600,600);
     
    	 jDialog1.setLayout(null);
     
    	 jDialog1.add(ok);
         ok.setBounds(90, 140, 70, 23);
         ok.setText("Ok");
         ok.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
                 try {
    					okActionPerformed(evt);
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
             }
         });
     
         jDialog1.add(annuler);
         annuler.setBounds(190, 140, 80, 23);
         annuler.setText("Annuler");
         annuler.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
                 annulerActionPerformed(evt);
             }
         });
     
         jLabel1.setText("Nom Enseignant :");
         jDialog1.add(jLabel1);
         jLabel1.setBounds(80, 20, 80, 15);
     
         jLabel2.setText("Module :");
         jDialog1.add(jLabel2);
         jLabel2.setBounds(80, 80, 90, 15);
     
         jLabel3.setText("Etat du paiement :");
         jDialog1.add(jLabel3);
         jLabel3.setBounds(80, 80, 90, 15);
     
         jLabel4.setText("Date de majoration :");
         jDialog1.add(jLabel4);
         jLabel4.setBounds(80, 80, 90, 15);
     
         jLabel5.setText("Heures prevues :");
         jDialog1.add(jLabel5);
         jLabel5.setBounds(80, 80, 90, 15);
     
         jLabel6.setText("Heures effectuees :");
         jDialog1.add(jLabel6);
         jLabel6.setBounds(80, 80, 90, 15);
     
         Nom_Enseignant.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
            	 Nom_EnseignantActionPerformed(evt);
             }
         });
     
         jDialog1.add(Nom_Enseignant);
         Nom_Enseignant.setBounds(80, 40, 200, 20);
     
         jDialog1.add(Module);
         Module.setBounds(80, 100, 200, 22);
     
         jDialog1.add(Etat_paiement);
         Etat_paiement.setBounds(80, 100, 200, 22);
     
         jDialog1.add(Date_majoration);
         Date_majoration.setBounds(80, 100, 200, 22);
     
         jDialog1.add(Heures_prevues);
         Heures_prevues.setBounds(80, 100, 200, 22);
     
         jDialog1.add(Heures_effectuees);
         Heures_effectuees.setBounds(80, 100, 200, 22);
     
     
         getContentPane().add(jDialog1);
         jDialog1.setBounds(0, 0, 400, 400);
     
         java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
         setBounds((screenSize.width-374)/2, (screenSize.height-232)/2, 374, 232);
     }
     
     private void Nom_EnseignantActionPerformed(java.awt.event.ActionEvent evt) {
     }
     
     private void annulerActionPerformed(java.awt.event.ActionEvent evt) {
        dispose();
     }
     
     private void okActionPerformed(java.awt.event.ActionEvent evt) throws Exception {//GEN-FIRST:event_okActionPerformed
     		String Enseignant = Nom_Enseignant.getText();
    		String module = Module.getText();
    		int EtatP = Integer.parseInt(Etat_paiement.getText());
    		Date dateActuelle = new Date();
    		int hp = Integer.parseInt(Heures_prevues.getText());
    		int he = Integer.parseInt(Heures_effectuees.getText());
     
    		AjoutS(Enseignant, module, EtatP , dateActuelle, hp, he);
    		jDialog1.setVisible(true);
     
     }
    et les erreurs que j'ai sont:
    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
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at java.awt.Container.addImpl(Unknown Source)
    	at java.awt.Container.add(Unknown Source)
    	at javax.swing.JDialog.addImpl(Unknown Source)
    	at java.awt.Container.add(Unknown Source)
    	at my_sql.Mysql.AjouterSActionPerformed(Mysql.java:593)
    	at my_sql.Mysql.access$2(Mysql.java:566)
    	at my_sql.Mysql$3.actionPerformed(Mysql.java:494)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)

  2. #2
    Membre Expert Avatar de maxf1
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 229
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Moselle (Lorraine)

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 229
    Par défaut
    la réponse est la :

    at my_sql.Mysql.AjouterSActionPerformed(Mysql.java:593)

    A toi de voir ce qu'est la ligne 593! On peux pas le deviner à ta place. Vu l'erreur tu pourrais quand meme faire un effort de recherche, car ton erreur ne doit pas etre trop compliquer à comprendre vu que c'est un NULLPOINTER!

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    296
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 296
    Par défaut
    Si je l'avais trouvé, je n'aurais pas posté.

  4. #4
    Membre émérite
    Avatar de sironimo
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    669
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2004
    Messages : 669
    Par défaut
    Alors tu dois apprendre à bien regarder le message d'erreur. Il t'indique souvent la ligne qui pose problème

    On peut savoir ce qu'il y a à la ligne en question?

  5. #5
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    296
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 296
    Par défaut
    A la ligne en question il y a :

  6. #6
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    296
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 296
    Par défaut
    Et a la ligne 566 il a y:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      private void AjouterSActionPerformed(java.awt.event.ActionEvent evt) {
    Et a 494 il y a:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    AjouterSActionPerformed(evt);

  7. #7
    Membre émérite
    Avatar de sironimo
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    669
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2004
    Messages : 669
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
     jDialog1.add(ok);
         ok.setBounds(90, 140, 70, 23);
         ok.setText("Ok");
         ok.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
                 try {
    					okActionPerformed(evt);
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
             }
         });
    Essaie de rajouter ton bouton a ton JDialog après l'actionListener()

    --> mettre jDialog1.add(ok); à la fin du code que j'ai copié et surtout enlevé la première ligne du code que j'ai mis.

  8. #8
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    296
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 296
    Par défaut
    je l'ai essayé mais il fait descendre l'erreur à la ligne suivante qui est :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ok.setBounds(90, 140, 70, 23);

  9. #9
    Membre émérite
    Avatar de sironimo
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    669
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2004
    Messages : 669
    Par défaut
    Tu as du définir ton bouton ok plus tôt dans ton code. Comment l'as tu défini?

  10. #10
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    296
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 296
    Par défaut
    je l'ai définit comme suit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ok = new javax.swing.JButton();

  11. #11
    Membre émérite
    Avatar de sironimo
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    669
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2004
    Messages : 669
    Par défaut
    Essaie plutôt comme ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    import javax.swing.*;
    .....
    .....
    JButton ok = new JButton("Ok");
    .....
    .....
    Si ça marche tu devras reprendre cette démarche dans tout ton code ie ajouter le compsoant au panneau après avoir spécifié ses caractéristiques et le déclarer comme ci-dessus.

    JComposant monCompsant = new JComposant("texte ici");

    A savoir que le Jcomposant est un nom générique que j'emploie pour tous les composants que tu peux utiliser du style JLabel, JTextField bref tu remplaces le nom générique JComposant par le composant qu'il faut

    Citation Envoyé par mariafan
    le code est le suivant:

    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
    private void initComponents() {                          
           jPanel = new javax.swing.JPanel();
           Services = new javax.swing.JButton();
           Heures_Dispo = new javax.swing.JButton();
           tableau = new javax.swing.JPanel();
           jScrollPane1 = new javax.swing.JScrollPane();
           jTable1 = new javax.swing.JTable();
           Ajouter_service = new javax.swing.JButton();
           jDialog1 = new javax.swing.JDialog();
     
     
           //frame Ajouter
           ok = new javax.swing.JButton();
     
           annuler = new javax.swing.JButton();
           jPanel1 = new javax.swing.JPanel();
           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();
           Nom_Enseignant = new javax.swing.JTextField();
           Module = new javax.swing.JTextField();
           Etat_paiement = new javax.swing.JTextField();
           Date_majoration = new javax.swing.JTextField();
           Heures_prevues = new javax.swing.JTextField();
           Heures_effectuees = new javax.swing.JTextField();
    Rien ne te choque entre ce que je t'ai dit et ton code??

    Je veux bien aider mais bon...

  12. #12
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    296
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 296
    Par défaut
    ça ne marche pas , il me met l'erreur à la ligne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    getContentPane().add(jDialog1);

  13. #13
    Membre émérite
    Avatar de sironimo
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    669
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2004
    Messages : 669
    Par défaut
    Tu as fait aussi
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    JDialog monJDialog = new JDialog();
    Essaie aussi d'ajouter ton jdialog1 a ton contentPane une fois que tu as fini de remplir ton jdialog1 ie que tu n'as plus de jdialog1.add() à faire.

  14. #14
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    296
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 296
    Par défaut
    j'ai toujours la même erreur mais ce qui est nouveau est:
    il ne m'affiche rien lors du premier clic mais lors du deuxiéme il m'affiche correctement la fenêtre. je ne comprends pas pourquoi?

  15. #15
    Membre émérite
    Avatar de sironimo
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    669
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2004
    Messages : 669
    Par défaut
    Montre maintenant à quoi ressemble ton code, celui des deux fenêtres, ie de la première fenêtre et du JDialog que tu ouvres après.

  16. #16
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    296
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 296
    Par défaut
    le code est le suivant:

    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
    private void initComponents() {                          
           jPanel = new javax.swing.JPanel();
           Services = new javax.swing.JButton();
           Heures_Dispo = new javax.swing.JButton();
           tableau = new javax.swing.JPanel();
           jScrollPane1 = new javax.swing.JScrollPane();
           jTable1 = new javax.swing.JTable();
           Ajouter_service = new javax.swing.JButton();
           jDialog1 = new javax.swing.JDialog();
     
     
           //frame Ajouter
           ok = new javax.swing.JButton();
     
           annuler = new javax.swing.JButton();
           jPanel1 = new javax.swing.JPanel();
           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();
           Nom_Enseignant = new javax.swing.JTextField();
           Module = new javax.swing.JTextField();
           Etat_paiement = new javax.swing.JTextField();
           Date_majoration = new javax.swing.JTextField();
           Heures_prevues = new javax.swing.JTextField();
           Heures_effectuees = new javax.swing.JTextField();
     
     
           getContentPane().setLayout(null);
     
           setTitle("Actions sur la BDD");
           setResizable(false);
           addWindowListener(new java.awt.event.WindowAdapter() {
               public void windowClosing(java.awt.event.WindowEvent evt) {
                   exitForm(evt);
               }
           });
     
           jPanel.setLayout(null);
     
           Services.setText("Services");
           Services.addActionListener(new java.awt.event.ActionListener() {
               public void actionPerformed(java.awt.event.ActionEvent evt) {
                   VisuActionPerformed(evt);
               }
           });
     
           jPanel.add(Services);
           Services.setBounds(530, 220, 110, 23);
           tableau.setLayout(null);
     
           tableau.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
           jTable1.setModel(new javax.swing.table.DefaultTableModel(
               new Object [][] {
                   {null, null, null, null},
                   {null, null, null, null},
                   {null, null, null, null},
                   {null, null, null, null}
               },
               new String [] {
                   "Title 1", "Title 2", "Title 3", "Title 4"
               }
           ));
           jScrollPane1.setViewportView(jTable1);
     
           tableau.add(jScrollPane1);
           jScrollPane1.setBounds(0, 0, 490, 90);
     
           jPanel.add(tableau);
           tableau.setBounds(30, 20, 490, 90);
     
           Ajouter_service.setText("Ajouter un service");
           Ajouter_service.addActionListener(new java.awt.event.ActionListener() {
               public void actionPerformed(java.awt.event.ActionEvent evt) {
                   AjouterSActionPerformed(evt);
               }
           });
     
           jPanel.add(Ajouter_service);
           Ajouter_service.setBounds(300, 330, 140, 23);
     
           getContentPane().add(jPanel);
           jPanel.setBounds(0, 0, 670, 460);
     
           java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
           setBounds((screenSize.width-661)/2, (screenSize.height-395)/2, 661, 395);
       }                          
     
       private void VisuActionPerformed(java.awt.event.ActionEvent evt) {                                           
           // Effacer le panel tableau 
           tableau.removeAll() ;
           // elle prends en argument le resultat de l'execution de la requete
           table = Tab(Visu()) ;
           sp = new javax.swing.JScrollPane(table) ;
           // On definit la taille et la position du tableau à afficher
           sp.setBounds(0,0,490,90) ;
           tableau.add(sp) ;
           // Raffraîchissement du panel
           tableau.setVisible(false) ;
           tableau.setVisible(true) ;
     
       }
      private void AjouterSActionPerformed(java.awt.event.ActionEvent evt) {
     
    	   getContentPane().setLayout(null);
     
           jDialog1.setTitle("Ajouter un Service");
           jDialog1.setResizable(false);
           addWindowListener(new java.awt.event.WindowAdapter() {
               public void windowClosing(java.awt.event.WindowEvent evt) {
                   exitForm(evt);
               }
           });
       	jDialog1.setVisible(true);
       	 jDialog1.setSize(600,600);
     
    	 jDialog1.setLayout(null);
     
     
         ok.setBounds(90, 500, 70, 23);
         ok.setText("Ok");
         ok.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
                 try {
    					okActionPerformed(evt);
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
             }
         });
         jDialog1.add(ok);
     
     
         annuler.setBounds(190, 500, 80, 23);
         annuler.setText("Annuler");
         annuler.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
                 annulerActionPerformed(evt);
             }
         });
         jDialog1.add(annuler);
     
         jLabel1.setText("Nom Enseignant :");
         jDialog1.add(jLabel1);
         jLabel1.setBounds(80, 20, 200, 20);
     
         jLabel2.setText("Module :");
         jDialog1.add(jLabel2);
         jLabel2.setBounds(80, 60, 200, 20);
     
         jLabel3.setText("Etat du paiement :");
         jDialog1.add(jLabel3);
         jLabel3.setBounds(80, 100, 200, 20);
     
         jLabel4.setText("Date de majoration :");
         jDialog1.add(jLabel4);
         jLabel4.setBounds(80, 140, 200, 20);
     
         jLabel5.setText("Heures prevues :");
         jDialog1.add(jLabel5);
         jLabel5.setBounds(80, 180, 200, 20);
     
         jLabel6.setText("Heures effectuees :");
         jDialog1.add(jLabel6);
         jLabel6.setBounds(80, 220, 200, 20);
     
         Nom_Enseignant.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
            	 Nom_EnseignantActionPerformed(evt);
             }
         });
     
         jDialog1.add(Nom_Enseignant);
         Nom_Enseignant.setBounds(80, 40, 200, 22);
     
         jDialog1.add(Module);
         Module.setBounds(80, 80, 200, 22);
     
         jDialog1.add(Etat_paiement);
         Etat_paiement.setBounds(80, 120, 200, 22);
     
         jDialog1.add(Date_majoration);
         Date_majoration.setBounds(80, 160, 200, 22);
     
         jDialog1.add(Heures_prevues);
         Heures_prevues.setBounds(80, 200, 200, 22);
     
         jDialog1.add(Heures_effectuees);
         Heures_effectuees.setBounds(80, 240, 200, 22);
     
     
         getContentPane().add(jDialog1);
         jDialog1.setBounds(0, 0, 400, 400);
     
         java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
         setBounds((screenSize.width-374)/2, (screenSize.height-232)/2, 374, 232);
     }
     
     private void Nom_EnseignantActionPerformed(java.awt.event.ActionEvent evt) {
     }
     
     private void annulerActionPerformed(java.awt.event.ActionEvent evt) {
        dispose();
     }
     
     private void okActionPerformed(java.awt.event.ActionEvent evt) throws Exception {
     		String Enseignant = Nom_Enseignant.getText();
    		String module = Module.getText();
    		int EtatP = Integer.parseInt(Etat_paiement.getText());
    		Date dateActuelle = new Date();
    		int hp = Integer.parseInt(Heures_prevues.getText());
    		int he = Integer.parseInt(Heures_effectuees.getText());
     
    		AjoutS(Enseignant, module, EtatP , dateActuelle, hp, he);
    		jDialog1.setVisible(true);
     
     }
       private void exitForm(java.awt.event.WindowEvent evt) {                          
           System.exit(0);
       }
    Avec ce code je n'ai pas la fenêtre lors du premier clic mais lors du deuxiéme et je n'arrive pas à ajouter le service dans ma base de données.

  17. #17
    Membre émérite
    Avatar de sironimo
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    669
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2004
    Messages : 669
    Par défaut
    Citation Envoyé par sironimo
    Essaie plutôt comme ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    import javax.swing.*;
    .....
    .....
    JButton ok = new JButton("Ok");
    .....
    .....
    Si ça marche tu devras reprendre cette démarche dans tout ton code ie ajouter le compsoant au panneau après avoir spécifié ses caractéristiques et le déclarer comme ci-dessus.

    JComposant monCompsant = new JComposant("texte ici");

    A savoir que le Jcomposant est un nom générique que j'emploie pour tous les composants que tu peux utiliser du style JLabel, JTextField bref tu remplaces le nom générique JComposant par le composant qu'il faut

    Citation Envoyé par mariafan
    le code est le suivant:

    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
    private void initComponents() {                          
           jPanel = new javax.swing.JPanel();
           Services = new javax.swing.JButton();
           Heures_Dispo = new javax.swing.JButton();
           tableau = new javax.swing.JPanel();
           jScrollPane1 = new javax.swing.JScrollPane();
           jTable1 = new javax.swing.JTable();
           Ajouter_service = new javax.swing.JButton();
           jDialog1 = new javax.swing.JDialog();
     
     
           //frame Ajouter
           ok = new javax.swing.JButton();
     
           annuler = new javax.swing.JButton();
           jPanel1 = new javax.swing.JPanel();
           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();
           Nom_Enseignant = new javax.swing.JTextField();
           Module = new javax.swing.JTextField();
           Etat_paiement = new javax.swing.JTextField();
           Date_majoration = new javax.swing.JTextField();
           Heures_prevues = new javax.swing.JTextField();
           Heures_effectuees = new javax.swing.JTextField();
    Rien ne te choque entre ce que je t'ai dit et ton code??

    Je veux bien aider mais bon...

  18. #18
    Membre éclairé
    Inscrit en
    Décembre 2006
    Messages
    76
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 76
    Par défaut
    remplace ok par this.ok

  19. #19
    Membre éclairé Avatar de Spinoza23
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    328
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 328
    Par défaut
    Et tu n'a pas besoin a chaque fois de mettre javax.swing. ... partout.

Discussions similaires

  1. Affichage d'une fenêtre sans la barre d'outil
    Par itrione dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 21/06/2006, 00h43
  2. [C# 2]Affichage d'une fenêtre d'attente
    Par sarapis dans le forum Windows Forms
    Réponses: 6
    Dernier message: 03/06/2006, 01h18
  3. [C#] Problème d'affichage d'une fenêtre (event Load)
    Par PB-W dans le forum Windows Forms
    Réponses: 3
    Dernier message: 10/03/2006, 14h48
  4. pb affichage dans une fenêtre
    Par Mat 74 dans le forum Windows
    Réponses: 8
    Dernier message: 28/11/2005, 00h14

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