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 :

Probleme avec deux JComboBox


Sujet :

AWT/Swing Java

  1. #1
    Membre à l'essai
    Inscrit en
    Janvier 2006
    Messages
    11
    Détails du profil
    Informations forums :
    Inscription : Janvier 2006
    Messages : 11
    Points : 11
    Points
    11
    Par défaut Probleme avec deux JComboBox
    Ben voilà, dans un panel j'ai deux combobox. Qui me permet de selectionner un étudiant et un groupe mais le probleme c'est que lorsque je choisi un élèment je veux l'afficher dans mes textfield. Mais ici cela marche pas. es-ce du a l'emploie de 2 JComboBox ou non. Lorsque j'en ai que 1cela marche tres bien mais ici non

    voici mon code
    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
    package classes;
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
     
    public class AjoutEleveGroupe extends JPanel implements ActionListener,ItemListener 
    {
     
        JFrame parent;
        String nomcours,niveaucours;
        Vector Etudiants=new Vector();
        Vector Courss=new Vector();
        Vector Groupess=new Vector();
        EtudiantDB tousetudiants=new EtudiantDB();
        CoursDB touscours=new CoursDB();
        GroupeDB tousgroupes=new GroupeDB();
        CardLayout cl=new CardLayout();
        JLabel jLabel1 = new JLabel();
        JLabel jLabel2 = new JLabel();
        JComboBox ComboEtudiant = new JComboBox();
        JLabel jLabel4 = new JLabel();
        JComboBox ComboGroupe = new JComboBox();
        DefaultComboBoxModel defaultt=new DefaultComboBoxModel();
        DefaultComboBoxModel defaulttt=new DefaultComboBoxModel();
        JLabel L_id_groupe = new JLabel();
        JLabel L_id_cours = new JLabel();
        JLabel L_nom_cours = new JLabel();
        JLabel L_niveau_cours = new JLabel();
        JLabel L_id_etudiant = new JLabel();
        JLabel L_nom_etudiant = new JLabel();
        JLabel L_prenom_etudiant = new JLabel();
        JTextField id_groupe = new JTextField();
        JTextField id_cours = new JTextField();
        JTextField nom_cours = new JTextField();
        JTextField niveau_cours = new JTextField();
        JTextField id_etudiant = new JTextField();
        JTextField nom_etudiant = new JTextField();
        JTextField prenom_etudiant = new JTextField();
        JButton Ajout = new JButton();
        JButton retour = new JButton();
        JButton OK1=new JButton();
     
        public AjoutEleveGroupe(JFrame parent,CardLayout cl) 
        {
            try 
            {
                this.parent=parent;
                this.cl=cl;
                jbInit();
            } 
            catch (Exception exception) 
            {
                exception.printStackTrace();
            }
        }
     
        private void jbInit() throws Exception {
            this.setLayout(null);
            this.setBackground(Color.lightGray);
            jLabel1.setFont(new java.awt.Font("Berlin Sans FB", Font.BOLD, 16));
            jLabel1.setForeground(Color.red);
            jLabel1.setText("Ajout d\'un etudiant dans un groupe");
            jLabel1.setBounds(new Rectangle(220, 25, 285, 40));
            jLabel2.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN, 14));
            jLabel2.setForeground(Color.red);
            jLabel2.setText("Choix de l\'étudiant");
            jLabel2.setBounds(new Rectangle(70, 70, 120, 20));
            Etudiants=EtudiantDB.recupTout();
                if(Etudiants.size()>0)
                {
                    for(int i=0;i<Etudiants.size();i++)
                    {
                        tousetudiants=(EtudiantDB)Etudiants.get(i);
                        String ajoutt=tousetudiants.getId()+" - "+tousetudiants.getNom()+"-"+tousetudiants.getPrenom();
                        defaultt.addElement(ajoutt);
                    }
                    ComboEtudiant.setModel(defaultt);
                }
                else
                {
                    JOptionPane.showMessageDialog(parent,"D'étudiant inscrit","",JOptionPane.INFORMATION_MESSAGE);
                }
            ComboEtudiant.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN,
                                                    11));
            ComboEtudiant.setForeground(Color.red);
            ComboEtudiant.setBounds(new Rectangle(70, 100, 360, 20));
            jLabel4.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN, 14));
            jLabel4.setForeground(Color.red);
            jLabel4.setText("Choix du groupe");
            jLabel4.setBounds(new Rectangle(70, 600, 111, 20));
            Groupess=GroupeDB.recupTout();
                if(Groupess.size()>0)
                {
                    for(int i=0;i<Groupess.size();i++)
                    {
                        tousgroupes=(GroupeDB)Groupess.get(i);
                        String ajoutt=tousgroupes.getId()+" - "+tousgroupes.getNom()+"-"+tousgroupes.getNomCours()+" "+tousgroupes.getNiveauCours();
                        defaulttt.addElement(ajoutt);
                    }
                    ComboGroupe.setModel(defaulttt);
                }
                else
                {
                    JOptionPane.showMessageDialog(parent,"D'étudiant inscrit","",JOptionPane.INFORMATION_MESSAGE);
                }
            ComboGroupe.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN, 11));
            ComboGroupe.setForeground(Color.red);
            ComboGroupe.setBounds(new Rectangle(70, 630, 360, 20));
            L_id_groupe.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN, 11));
            L_id_groupe.setForeground(Color.red);
            L_id_groupe.setText("ID_GROUPE:");
            L_id_groupe.setBounds(new Rectangle(70, 250, 110, 20));
            L_id_cours.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN, 11));
            L_id_cours.setForeground(Color.red);
            L_id_cours.setText("ID_COURS:");
            L_id_cours.setBounds(new Rectangle(70, 280, 110, 20));
            L_nom_cours.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN, 11));
            L_nom_cours.setForeground(Color.red);
            L_nom_cours.setText("NOM_COURS:");
            L_nom_cours.setBounds(new Rectangle(70, 310, 110, 20));
            L_niveau_cours.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN,
                                                     11));
            L_niveau_cours.setForeground(Color.red);
            L_niveau_cours.setText("NIVEAU_COURS:");
            L_niveau_cours.setBounds(new Rectangle(70, 340, 110, 20));
            L_id_etudiant.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN,
                                                    11));
            L_id_etudiant.setForeground(Color.red);
            L_id_etudiant.setText("ID_ETUDIANT:");
            L_id_etudiant.setBounds(new Rectangle(70, 130, 110, 20));
            L_nom_etudiant.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN,
                                                     11));
            L_nom_etudiant.setForeground(Color.red);
            L_nom_etudiant.setText("NOM_ETUDIANT:");
            L_nom_etudiant.setBounds(new Rectangle(70, 160, 100, 20));
            L_prenom_etudiant.setFont(new java.awt.Font("Berlin Sans FB",
                    Font.PLAIN, 11));
            L_prenom_etudiant.setForeground(Color.red);
            L_prenom_etudiant.setText("PRENOM_ETUDIANT:");
            L_prenom_etudiant.setBounds(new Rectangle(70, 190, 110, 27));
            id_groupe.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN, 12));
            id_groupe.setBounds(new Rectangle(185, 250, 20, 20));
            id_cours.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN, 12));
            id_cours.setBounds(new Rectangle(185, 280, 20, 20));
            nom_cours.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN, 12));
            nom_cours.setBounds(new Rectangle(185, 310, 100, 20));
            niveau_cours.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN, 12));
            niveau_cours.setBounds(new Rectangle(185, 340, 150, 20));
            id_etudiant.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN, 12));
            id_etudiant.setBounds(new Rectangle(185, 130, 20, 20));
            nom_etudiant.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN, 12));
            nom_etudiant.setBounds(new Rectangle(185, 160, 150, 20));
            prenom_etudiant.setFont(new java.awt.Font("Berlin Sans FB", Font.PLAIN,
                                                      12));
            prenom_etudiant.setBounds(new Rectangle(185, 190, 150, 20));
            Ajout.setBounds(new Rectangle(120, 490, 130, 40));
            Ajout.setText("Ajouter");
            retour.setBounds(new Rectangle(280, 490, 130, 40));
            retour.setText("Retour");
            retour.addActionListener(this);
            OK1.setBounds(new Rectangle(500,100,70,30));
            OK1.setText("OK");
            this.add(jLabel1);
            this.add(jLabel2);
            this.add(ComboEtudiant);
            this.add(jLabel4);
            this.add(ComboGroupe);
            this.add(L_id_cours);
            this.add(L_id_groupe);
            this.add(L_nom_cours);
            this.add(L_niveau_cours);
            this.add(L_id_etudiant);
            this.add(L_nom_etudiant);
            this.add(L_prenom_etudiant);
            this.add(id_groupe);
            this.add(id_cours);
            this.add(nom_cours);
            this.add(niveau_cours);
            this.add(id_etudiant);
            this.add(nom_etudiant);
            this.add(prenom_etudiant);
            this.add(Ajout);
            this.add(retour);
            this.add(OK1);
        }
     
        public void actionPerformed(ActionEvent e)
        {
            if(e.getSource()==Ajout)
            {
     
            }
            if(e.getSource()==retour)
            {
                cl.show(parent.getContentPane(),"demarrage");
            }
        }
     
        public void itemStateChanged(ItemEvent e)
        {
            if(e.getSource()==ComboEtudiant)
            {
                int i=ComboEtudiant.getSelectedIndex();
                tousetudiants=(EtudiantDB)Etudiants.get(i);
                String idetudiants=Integer.toString(tousetudiants.getId());
                id_etudiant.setText(idetudiants);
                nom_etudiant.setText(tousetudiants.getNom());
                prenom_etudiant.setText(tousetudiants.getPrenom());
                id_etudiant.setEditable(false);
                nom_etudiant.setEditable(false);
                prenom_etudiant.setEditable(false);
     
     
            }
            else if(e.getSource()==ComboGroupe)
            {
                int i=ComboGroupe.getSelectedIndex();
                tousgroupes=(GroupeDB)Groupess.get(i);
                String idCl=Integer.toString(tousgroupes.getId());
                id_groupe.setText(idCl);
                String idcour=Integer.toString(tousgroupes.getIdCours());
                id_cours.setText(idcour);
                nom_cours.setText(tousgroupes.getNomCours());
                niveau_cours.setText(tousgroupes.getNiveauCours());
                id_groupe.setEditable(false);
                id_cours.setEditable(false);
                nom_cours.setEditable(false);
                niveau_cours.setEditable(false);
            }
        }
    }

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 77
    Points : 84
    Points
    84
    Par défaut
    Ce serait bien de cibler ta question... tout ce code...

  3. #3
    Expert éminent sénior
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Points : 21 324
    Points
    21 324
    Par défaut
    Tu vas forcément avoir de la peine à récupérer tes événements, puisque tu n'ajoutes pas de listener à tes JComboBox

  4. #4
    Membre à l'essai
    Inscrit en
    Janvier 2006
    Messages
    11
    Détails du profil
    Informations forums :
    Inscription : Janvier 2006
    Messages : 11
    Points : 11
    Points
    11
    Par défaut
    Merci

  5. #5
    Expert éminent sénior
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Points : 21 324
    Points
    21 324
    Par défaut
    Citation Envoyé par zandb69
    Merci
    Derien et oublie pas

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

Discussions similaires

  1. Probleme avec deux tableaux
    Par thaundeadboss dans le forum Balisage (X)HTML et validation W3C
    Réponses: 0
    Dernier message: 17/09/2009, 15h20
  2. probleme avec un JComboBox et une JTable
    Par claire13 dans le forum Composants
    Réponses: 8
    Dernier message: 25/04/2008, 15h29
  3. Probleme avec deux div dans une autre
    Par orphen dans le forum Mise en page CSS
    Réponses: 3
    Dernier message: 05/11/2007, 15h10
  4. Probleme avec une JComboBox et ComboBoxModel
    Par bassim dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 23/09/2007, 13h44
  5. probleme avec deux fiches
    Par youcef_b_dz dans le forum Bases de données
    Réponses: 5
    Dernier message: 24/08/2006, 17h33

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