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 :

utilisation de JComboBox en parametre d'une methode java


Sujet :

Java

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2015
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2015
    Messages : 55
    Points : 43
    Points
    43
    Par défaut utilisation de JComboBox en parametre d'une methode java
    Bonjour,

    Pourriez vous m'aider sur le probleme suivant: j'ai un message d'erreur lorsque j'essaie d'utiliser un JCombo box en parametre.

    J'ai simplifié ma methode pour le forum.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
        public void miseAJourComboBox(JComboBox<String> jcb){
            System.out.println("hi");
        }
    Cette methode renvoit le message suivant:

    error: cannot find symbol
    public void miseAJourComboBox(JComboBox<String> jcb){
    symbol: class JComboBox
    location: class FrameAchat

    Voici mon code complet de la classe dans laquelle j'ai cette methode:

    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
     
    /*
     * 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 gestionconcessionsportapp;
     
    /**
     *
     * @author CLV
     */
    public class FrameAchat extends javax.swing.JFrame {
     
        public ConnectionSQL connectionSQL;
     
        /** Creates new form FrameAchat */
        public FrameAchat() {
            connectionSQL = new ConnectionSQL();
            System.out.println("passe par constructeur de achat");
            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() {
     
            jLabelFicheAchat = new javax.swing.JLabel();
            jComboIdPdt = new javax.swing.JComboBox<>();
            jLabelMarque = new javax.swing.JLabel();
            jLabelModele = new javax.swing.JLabel();
            jLabelAnnee = new javax.swing.JLabel();
            jLabelPrix = new javax.swing.JLabel();
            jComboIdFrs = new javax.swing.JComboBox<>();
            jLabelNom = new javax.swing.JLabel();
            jComboQte = new javax.swing.JComboBox<>();
            jLabelQte = new javax.swing.JLabel();
            Achat = new javax.swing.JButton();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            jLabelFicheAchat.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
            jLabelFicheAchat.setText("Creation Achat");
     
            jComboIdPdt.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
     
            jLabelMarque.setText("jLabel1");
     
            jLabelModele.setText("jLabel1");
     
            jLabelAnnee.setText("jLabel1");
     
            jLabelPrix.setText("jLabel1");
     
            jComboIdFrs.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
     
            jLabelNom.setText("jLabel1");
     
            jComboQte.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
     
            jLabelQte.setText("Quantité:");
     
            Achat.setText("ACHETER");
     
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jLabelFicheAchat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 177, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(91, 91, 91))
                .add(layout.createSequentialGroup()
                    .add(24, 24, 24)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                            .add(jComboIdPdt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(53, 53, 53)
                            .add(jLabelMarque)
                            .add(18, 18, 18)
                            .add(jLabelModele)
                            .add(28, 28, 28)
                            .add(jLabelAnnee)
                            .add(18, 18, 18)
                            .add(jLabelPrix))
                        .add(layout.createSequentialGroup()
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(jComboIdFrs, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jLabelQte))
                            .add(53, 53, 53)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(jComboQte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jLabelNom)
                                .add(Achat))))
                    .addContainerGap(66, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(21, 21, 21)
                    .add(jLabelFicheAchat)
                    .add(18, 18, 18)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jComboIdPdt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jLabelMarque)
                        .add(jLabelModele)
                        .add(jLabelAnnee)
                        .add(jLabelPrix))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jComboIdFrs, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jLabelNom))
                    .add(18, 18, 18)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jComboQte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jLabelQte))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 76, Short.MAX_VALUE)
                    .add(Achat)
                    .add(51, 51, 51))
            );
     
            pack();
        }// </editor-fold>                        
     
        /**
         * @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(FrameAchat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(FrameAchat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(FrameAchat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(FrameAchat.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 FrameAchat().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify                     
        private javax.swing.JButton Achat;
        private javax.swing.JComboBox<String> jComboIdFrs;
        private javax.swing.JComboBox<String> jComboIdPdt;
        private javax.swing.JComboBox<String> jComboQte;
        private javax.swing.JLabel jLabelAnnee;
        private javax.swing.JLabel jLabelFicheAchat;
        private javax.swing.JLabel jLabelMarque;
        private javax.swing.JLabel jLabelModele;
        private javax.swing.JLabel jLabelNom;
        private javax.swing.JLabel jLabelPrix;
        private javax.swing.JLabel jLabelQte;
        // End of variables declaration                   
     
        public void miseAJourComboBox(JComboBox<String> jcb){
            System.out.println("hi");
        }
     
     
    }
    Merci
    Cedric

  2. #2
    Membre averti
    Homme Profil pro
    Architecte technique
    Inscrit en
    Mai 2020
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte technique

    Informations forums :
    Inscription : Mai 2020
    Messages : 325
    Points : 436
    Points
    436
    Par défaut
    Vous n'avez aucun import de cette classe JComboBox. Il faut soit l'importer soit utiliser le nom qualifié dans votre signature de méthode: public void miseAJourComboBox(avax.swing.JComboBox<String> jcb){

  3. #3
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2015
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2015
    Messages : 55
    Points : 43
    Points
    43
    Par défaut
    Merci, ca marche! bonne soiree

  4. #4
    Membre averti
    Homme Profil pro
    Architecte technique
    Inscrit en
    Mai 2020
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte technique

    Informations forums :
    Inscription : Mai 2020
    Messages : 325
    Points : 436
    Points
    436
    Par défaut
    Bonjour,

    N'oubliez pas de marquer votre question comme résolue si vous avez une solution.

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

Discussions similaires

  1. Ajouter un DLL comme parametre dans une method
    Par charaf dans le forum VB.NET
    Réponses: 2
    Dernier message: 17/09/2007, 09h36
  2. Utilisation de final dans les parametres d'une methodes
    Par menzlitsh dans le forum Langage
    Réponses: 8
    Dernier message: 24/07/2007, 14h17
  3. Réponses: 7
    Dernier message: 16/03/2007, 19h28
  4. Réponses: 23
    Dernier message: 10/01/2007, 01h09
  5. valeur par defaut d'un parametre d'une methode
    Par le y@m's dans le forum C++
    Réponses: 16
    Dernier message: 04/05/2005, 20h23

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