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

avec Java Discussion :

peut on installer 2 ecouteurs dans une meme classe ?


Sujet :

avec Java

  1. #1
    Membre régulier Avatar de POKOU
    Homme Profil pro
    developpeur
    Inscrit en
    Décembre 2008
    Messages
    121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : developpeur

    Informations forums :
    Inscription : Décembre 2008
    Messages : 121
    Points : 101
    Points
    101
    Par défaut peut on installer 2 ecouteurs dans une meme classe ?
    Bonjour

    dans un Panel,
    je crée un Listener Interne,
    puis je positionne un ecouteur sur deux combobox.
    là j'obtiens un:
    Erreur IHM : java.lang.NullPointerException

    mon pbm vient du fait que le panel est instancié bien plus en amont dans la chaine et je veux pas y toucher. Je rajoute juste un filtre sur des groupes de courriers.

    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
    // ca c'est la liste qui affiche les courriers
      protected UTJInviteEntry typeDocIE;
    // ca c'est la liste qui affiche les groupes
      protected UTJComboBoxKeyed groupeCourriersCbk;
    // la dedans je stoque le choix du groupe
      protected static String groupeChoisi;
     
      public CreationCourrierPanel(ActionPanel action, FunctionFrame frame) {
        super(action, frame);
        communConstructor();
      }
      protected void communConstructor() {
        // construction IHM
        try  {
          initIHM();
        }
        catch(Exception e) {
          System.err.println("Erreur IHM : " + e);
          e.printStackTrace();
        }
      }
     
      protected void initIHM() throws Exception {
        // personnalisation des composants //
        this.detailPanel.setBordered();
        this.typeDocL.setText("Type document  : ");
        this.dateReceptionL.setText("Date réception : ");
        this.motifCb = new UTJComboBoxKeyed(MotifEvenement.getListeMotifVisible(), UTJComboBoxKeyed.STRING_EDITOR, 1, 20);
    // G - remplissage de la combo des groupes 
        this.groupeCourriersCbk = new UTJComboBoxKeyed(GroupeCourrierEvenement.getListeGroupesCourriers(), UTJComboBoxKeyed.STRING_EDITOR, 5, 40);
        groupeCourriersCbk.setSelectedItem((String)groupeCourriersCbk.getSelectedKey());
    //  pose ecouteur sur Combo groupe : il stocke la modif sur le code groupe
        this.groupeCourriersCbk.addActionListener( 
    			new ActionListener() {
    				public void actionPerformed(ActionEvent e){
    				    groupeCourriersCbk.setSelectedItem((String)groupeCourriersCbk.getSelectedKey());
    				    groupeChoisi = (String)groupeCourriersCbk.getSelectedKey();
    				}
    			}
        );
    //  pose ecouteur sur liste des courriers : il raffraichit la liste des courriers
        this.typeDocIE.addActionListener( 
        		new ActionListener() {
        			public void actionPerformed(ActionEvent e){
    // Construction invite type de document :
        				String[] columnNames = {"Code", "Libelle"};
        				int[] types = {UTJTable.TYPE_ALPHA, UTJTable.TYPE_ALPHA};
        				int[] taillesColonnes = {5,40};
        				int[] decim = {0,0};
        				int[] aligns = {SwingConstants.LEFT, SwingConstants.LEFT};
        				boolean[] zeroesView = {false, false};
        				UTJTable table = new UTJTable(columnNames, types, taillesColonnes, decim, aligns, zeroesView);
     
        				typeDocIE = new UTJInviteEntry("Choix du type de document", table,
        						TypeDocument.getListeDocumentsParGroupe(groupeChoisi), 0, 1, new UTKeyedItemString());
     
    					String[] fieldsNamesOfKey = {"BKCOTYDOCU"};
        				typeDocIE.setFieldsNamesOfKey(fieldsNamesOfKey);
        			    typeDocIE.setItemEntry(new UTKeyedItemString(getTypeDocument(), ""));
        			}
        		}
        );
    ...
    ma question est donc peut on avoir 2 ecouteurs issus d'un meme ListenerInterne dans une Vue ?
    # Do NOT simply read the instructions in here without understanding
    # what they do. They're here only as hints or reminders. If you are unsure
    # consult the online docs. You have been warned.

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    7
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 7
    Points : 15
    Points
    15
    Par défaut
    J'ai pas trop eu le temps de regarder en détail ton code, mais une simple question, pourquoi n'externalises-tu pas ton listener, dans ce cas?

  3. #3
    Membre régulier Avatar de POKOU
    Homme Profil pro
    developpeur
    Inscrit en
    Décembre 2008
    Messages
    121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : developpeur

    Informations forums :
    Inscription : Décembre 2008
    Messages : 121
    Points : 101
    Points
    101
    Par défaut
    Merci
    c'est une bonne piste
    il existe apparemment un listener en amont de ma classe panel et je vais essayer d'utiliser celui la.
    a+
    # Do NOT simply read the instructions in here without understanding
    # what they do. They're here only as hints or reminders. If you are unsure
    # consult the online docs. You have been warned.

  4. #4
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    106
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 106
    Points : 121
    Points
    121
    Par défaut
    Je viens de jeter un oeil a ton code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    this.typeDocIE.addActionListener
    A quel moment instancies-tu 'typeDocIE' ????

    La NullPointerException provient surement de lá
    Tu ne peux pas ajouter le listener si tu n'as pas instancié ta variable (qui est null par défaut)

  5. #5
    Membre régulier Avatar de POKOU
    Homme Profil pro
    developpeur
    Inscrit en
    Décembre 2008
    Messages
    121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : developpeur

    Informations forums :
    Inscription : Décembre 2008
    Messages : 121
    Points : 101
    Points
    101
    Par défaut
    merci de ta réponse
    je la déclare effectivement dans les déclarations, je met le 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
    ublic class CreationCourrierPanel extends FunctionPanel {
      // Définition des composants :
      protected CartoucheSelectionTiers tiersConcerneCart = new CartoucheSelectionTiers("Concerné :", true);
      protected CartoucheSelectionTiers tiersDestinataireCart = new CartoucheSelectionTiers("Destinataire", true);
      // DetailPanel
      protected UTJPanel detailPanel = new UTJPanel();
      protected UTJLabel motifL = new UTJLabel("Motif :  ");
      protected UTJComboBoxKeyed motifCb;
      protected UTJLabel dateReceptionL = new UTJLabel();
      protected UTJDateFieldP dateReceptionDf = new UTJDateFieldP();
      protected UTJLabel typeDocL = new UTJLabel();
      protected UTJInviteEntry typeDocIE;
     
    // GMO debut - declaration de la combo box de selection des groupe et stockage du groupe selectionné 
      protected UTJLabel groupeCourriersL = new UTJLabel("Groupe :  ");
      protected UTJComboBoxKeyed groupeCourriersCbk;
      protected static String groupeChoisi;
    // GMO fin
     
    // Contexte :
      protected Tiers tiersConcerne;
      protected Tiers tiersDestinataire;
     
      // gmo debut - declaration d'un listener interne pour ecouter sur le combobox du groupe
      public class ListenerInterne implements ActionListener{
    		public void actionPerformed(ActionEvent e) {
    			JOptionPane.showMessageDialog(null, "Choix du type de document");		
    		}
    	}
    // gmo fin
     
      /**
       * Constructeur vide
       */
      public CreationCourrierPanel() {
        communConstructor();
      }
      /**
       * Constructeur conseillé
       */
      public CreationCourrierPanel(ActionPanel action, FunctionFrame frame) {
        super(action, frame);
        communConstructor();
      }
      protected void communConstructor() {
        // construction IHM
        try  {
          initIHM();
        }
        catch(Exception e) {
          System.err.println("Erreur IHM : " + e);
          e.printStackTrace();
        }
      }
     
      protected void initIHM() throws Exception {
        // personnalisation des composants //
    pour l'instanciation je continue a chercher.
    # Do NOT simply read the instructions in here without understanding
    # what they do. They're here only as hints or reminders. If you are unsure
    # consult the online docs. You have been warned.

  6. #6
    Membre régulier Avatar de POKOU
    Homme Profil pro
    developpeur
    Inscrit en
    Décembre 2008
    Messages
    121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : developpeur

    Informations forums :
    Inscription : Décembre 2008
    Messages : 121
    Points : 101
    Points
    101
    Par défaut
    merci radtriste
    c'est ça j'ai déplacé mon code avec l'écouteur après l'instanciation et ça va mieux.
    # Do NOT simply read the instructions in here without understanding
    # what they do. They're here only as hints or reminders. If you are unsure
    # consult the online docs. You have been warned.

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

Discussions similaires

  1. Réponses: 8
    Dernier message: 11/11/2011, 08h55
  2. Réponses: 6
    Dernier message: 02/08/2009, 12h39
  3. Réponses: 2
    Dernier message: 27/03/2005, 16h09
  4. Réponses: 15
    Dernier message: 22/03/2005, 14h45
  5. Find et mv dans une même commande
    Par Yann21 dans le forum Linux
    Réponses: 3
    Dernier message: 28/02/2005, 10h49

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