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 :

Classique : thread "AWT-EventQueue-0"


Sujet :

AWT/Swing Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2011
    Messages
    84
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2011
    Messages : 84
    Par défaut Classique : thread "AWT-EventQueue-0"
    Salut tous le monde : )

    dans mon projet j'ai une Jframe dans laquelle on saisi 3 données (filière ,level,year )
    lorsque je clique sur OK et selon ces 3données saisies , on affiche une Jtable qui contient la liste correspondante jusqu'ici c'est bon
    mon problème c'est que lorsque je clique pour la première fois sur ok je vois bien ma jtable affichée ,et lorsque je clique pour la deuxieme fois je vois bien une nouvelle liste affichée(qui corresponde aux 3données saisies) mais lorsque je sélectionne une ligne ,je vois apparaitre une ligne de la liste précédente (cette liste n'existe plus normalement) avec l'erreur suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
    	at java.util.ArrayList.get(Unknown Source)
    j'ai lu cette article http://hugo.developpez.com/tutoriels...roblems-swing/ mais je n'ai pas trouvé une solution pratique

    je ne sais pas à quoi ça est dû ,
    votre aide s'il vous plait ,je suis bloqué

  2. #2
    Membre expérimenté
    Homme Profil pro
    Inscrit en
    Juillet 2012
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Bénin

    Informations forums :
    Inscription : Juillet 2012
    Messages : 200
    Par défaut
    Bonjour.
    Pourrais-tu montrer le code exécuté lors du clic sur le bouton? Ainsi il sera plus facile de t'aider.
    En général, une exception de type ArrayIndexOutOfBoundException survient lorsqu'on essaie d'accéder à un élément d'un tableau, d'une combo ou d'une liste et que l'indice utilisé est en dehors des limites valides.

  3. #3
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2011
    Messages
    84
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2011
    Messages : 84
    Par défaut
    Merci beaucoup ,
    voici mon code
    dans le constructeur de la classe UIEtudiant j'ai mis ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
        btnOk = new JButton("ok");
    		    btnOk.addActionListener(new ButtonListener());
         		btnOk.setBounds(507, 7, 53, 23);
    			panel.add(btnOk);
    et deux classes internes ButtonListner et MouseListener
    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
     
    	class ButtonListener implements ActionListener {
    						  ButtonListener() {
    						  }
     
    						  public void actionPerformed(ActionEvent e) {
    						    System.out.println("clicked");
     
    						    filSel = comboFiliere.getSelectedItem().toString();
    							levSel = comboLevel.getSelectedItem().toString();
    							yearSel = yearChooser.getYear()+"";
    							System.out.println("filiere " +filSel );
    							System.out.println("level " + levSel);
    							System.out.println("year "+ yearSel);
     
    							 modelEtudiant = new TableModelEtudiantFly(filSel,levSel,yearSel);
    							 tableGE = new JTable(modelEtudiant);
    							 scrollPaneGE = new JScrollPane(tableGE);
    							scrollPaneGE.setBounds(42, 11, 468, 115);
    						 	panel_1.add(scrollPaneGE);
     
    							panel_1.setVisible(true);
     
     
    							tableGE.addMouseListener(new Mouselistner());
     
     
    						   }
    		  }
     
     
     
    		class Mouselistner implements MouseListener{
     
    			public Mouselistner() {
    				// TODO Auto-generated constructor stub
    			}
     
    			@Override
    			public void mouseClicked(MouseEvent evt) {
    				System.out.println("Mouse clicked");
     
    				System.out.println("Ligne:" + tableGE.getSelectedRow());
    	        	rowSelected = tableGE.getSelectedRow();
    	        	System.out.println("Colonne:" + tableGE.getSelectedColumn());
     
    	            System.out.println(modelEtudiant.getEtudiant(rowSelected));
    	        	   etudiantSelected = modelEtudiant.getEtudiant(rowSelected);
     
    	        	if (evt.getClickCount() == 3) {
    	        	      System.out.println("triple-click");
    	        	    } 
    	        	else if (evt.getClickCount() == 2) {
     
    	        	      System.out.println("double-click");
     
    	        	      new FicheEtudiant(etudiantSelected).setVisible(true);
    	        	    }
     
     
     
    			}
    //  autres methodes implementées
    }
    en pièce jointe la classe UIEtudiant.
    Merci
    Fichiers attachés Fichiers attachés

  4. #4
    Expert confirmé
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Par défaut
    Bonjour,

    A quelle ligne exacte survient cette exception.
    Merci de nous mettre également à disposition la stacktrace complète de l'exception.

  5. #5
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2011
    Messages
    84
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2011
    Messages : 84
    Par défaut
    Salut , je vous remercie premièrement

    je rappelle que dans ma JFrame il y a deux parties :
    1ere Partie Saisie : là je saisie les 3donneées : filiere , niveau ,année d'etude.
    2eme Partie Affichage du resultats sous forme de Jtable associé au model.

    voici l'erreur :
    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
     
     
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
    	at java.util.ArrayList.get(Unknown Source)
    	at ma.ismp.gpedagogique.presentation.TableModelEtudiantFly.getEtudiant(TableModelEtudiantFly.java:104)
    	at ma.ismp.gpedagogique.presentation.UIEtudiant$Mouselistner.mouseClicked(UIEtudiant.java:209)
    	at java.awt.AWTEventMulticaster.mouseClicked(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.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(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)
    j'ai ajouté des println pour investigué et je suis surpris du fait que la liste que m'envoie le model subit une altération que je comprend pas

    voici un senario que j'ai testé :
    1erement mon jtable affiche 2 enregistrements (lignes) .
    ensuite j'envoie une requête qui affiche 1 ligne

    mais le probleme c'est quant je clique, la premiere liste revient °O
    voici le resultat complet sur la console

    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
     
    rowcount from model :2
    rowcount from model :2
    clicked  :1times 
    filiere Pêche
    level 1ere année
    year 2009
    from ModelFLY: Pêche   1ere année   2009
    Hibernate: select etudiant0_.etudiant_id as etudiant1_6_, etudiant0_.LIEU_DipAcces as LIEU2_6_, etudiant0_.MENTION_DipAcces as MENTION3_6_, etudiant0_.TYPE_DipAcces as TYPE4_6_, etudiant0_.etudiant_cin as etudiant5_6_, etudiant0_.etudiant_cne as etudiant6_6_, etudiant0_.etudiant_birth as etudiant7_6_, etudiant0_.etudiant_filiere as etudiant8_6_, etudiant0_.etudiant_level as etudiant9_6_, etudiant0_.etudiant_matricule as etudiant10_6_, etudiant0_.etudiant_nationalite as etudiant11_6_, etudiant0_.etudiant_nom as etudiant12_6_, etudiant0_.etudiant_prenom as etudiant13_6_, etudiant0_.etudiant_sexe as etudiant14_6_, etudiant0_.etudiant_YearInscription as etudiant15_6_ from ismp.etudiant etudiant0_ where etudiant0_.etudiant_filiere=? and etudiant0_.etudiant_level=? and etudiant0_.etudiant_YearInscription=?
    Hibernate: select modules0_.etudiant_id as etudiant7_6_1_, modules0_.module_id as module1_1_, modules0_.module_id as module1_7_0_, modules0_.etudiant_id as etudiant7_7_0_, modules0_.module_code as module2_7_0_, modules0_.module_desc as module3_7_0_, modules0_.module_isV as module4_7_0_, modules0_.module_nom as module5_7_0_, modules0_.module_note as module6_7_0_ from ismp.module modules0_ where modules0_.etudiant_id=?
    studentList from model(params) :[Etudiant [etudiantId=6, etudiantMatricule=matri6, etudiantLevel=1ere année, etudiantFiliere=Pêche, etudiantCne=CNE6, etudiantCin=CIN6, etudiantNom=NOM6, etudiantPrenom=prenom6, etudiantSexe=M, etudiantNationalite=Marocaine, etudiantDateBirth=1975-07-10, etudiantYearInscription=2009, EtudiantDipDacces=ma.ismp.gpedagogique.domain.embeddables.DiplomeDacces@6c3744bc, modules=[]]]
    loading model(params) ...
    rowcount from model :1
    row count from mousListner : 1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :1
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    Mouse clicked
    Ligne :-1
    Colonne :-1
    etudiantList from getEtudiant :[Etudiant [etudiantId=6, etudiantMatricule=matri6, etudiantLevel=1ere année, etudiantFiliere=Pêche, etudiantCne=CNE6, etudiantCin=CIN6, etudiantNom=NOM6, etudiantPrenom=prenom6, etudiantSexe=M, etudiantNationalite=Marocaine, etudiantDateBirth=1975-07-10, etudiantYearInscription=2009, EtudiantDipDacces=ma.ismp.gpedagogique.domain.embeddables.DiplomeDacces@6c3744bc, modules=[]]]
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
    	at java.util.ArrayList.get(Unknown Source)
    	at ma.ismp.gpedagogique.presentation.TableModelEtudiantFly.getEtudiant(TableModelEtudiantFly.java:104)
    	at ma.ismp.gpedagogique.presentation.UIEtudiant$Mouselistner.mouseClicked(UIEtudiant.java:209)
    	at java.awt.AWTEventMulticaster.mouseClicked(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.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(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)
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2
    rowcount from model :2

    voici ma classe UIEtudiant
    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
     
    package ma.ismp.gpedagogique.presentation;
     
    import java.awt.BorderLayout;
    import java.awt.EventQueue;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EmptyBorder;
    import javax.swing.border.EtchedBorder;
    import java.awt.SystemColor;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.JComboBox;
    import javax.swing.JButton;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
     
    import javax.swing.border.BevelBorder;
    import java.awt.Color;
    import javax.swing.JTable;
    import javax.swing.JScrollPane;
     
    import ma.ismp.gpedagogique.domain.model.Etudiant;
    import com.toedter.calendar.JYearChooser;
    import javax.swing.ImageIcon;
    import javax.swing.SwingConstants;
     
    public class UIEtudiant extends JFrame {
     
    	     private JPanel contentPane;
     
    		 private TableModelEtudiantFly modelEtudiant;
         	 private JTable tableGE;
    		 private int rowSelected;
    		private int click = 0;
     
    	  public Etudiant etudiantSelected;
     
         // public String filSel="";
          //public String levSel="";
          //public String yearSel="";
     
     	 public  JComboBox comboFiliere;
         public JComboBox comboLevel; 
         public  JYearChooser yearChooser;
         public JButton btnOk;
     	 public JPanel panel ;
     
     
     
     
    	public static void main(String[] args) {
    		EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				try {
    					UIEtudiant frame = new UIEtudiant();
    					frame.setVisible(true);
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
    			}
    		});
    	}
     
    	/**
             * Create the frame.
             */
    	  public UIEtudiant() {
     
     
     
    		setTitle("Gestion des \u00E9tudiants");
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setBounds(100, 100, 606, 300);
    		setLocation(410, 100);
    		contentPane = new JPanel();
    		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    		setContentPane(contentPane);
    		contentPane.setLayout(null);
     
    		panel = new JPanel();
    		panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, SystemColor.textHighlight));
    		panel.setBounds(10, 11, 570, 42);
    		contentPane.add(panel);
    		panel.setLayout(null);
     
    		JLabel lblFiliere = new JLabel("Fili\u00E8re :");
    		lblFiliere.setBounds(10, 11, 46, 14);
    		panel.add(lblFiliere);
     
    		String[] tab_filiere = {"Pêche","Machine","Industire de la P." } ;
    		String[] tab_level = {"1ere année","2eme année","3eme année", "4eme année" } ;
     
    		comboFiliere = new JComboBox(tab_filiere);
    		comboFiliere.setBounds(54, 8, 116, 20);
    		panel.add(comboFiliere);
     
    		JLabel lblNiveau = new JLabel("Niveau :");
    		lblNiveau.setBounds(197, 11, 46, 14);
    		panel.add(lblNiveau);
     
    	    comboLevel = new JComboBox(tab_level);
    		comboLevel.setBounds(244, 8, 97, 20);
    		panel.add(comboLevel);
     
     
     
     
    		JLabel lblAnne = new JLabel("Ann\u00E9e :");
    		lblAnne.setBounds(361, 11, 46, 14);
    		panel.add(lblAnne);
     
    	    yearChooser = new JYearChooser();
    		yearChooser.setBounds(404, 8, 47, 20);
    		panel.add(yearChooser);
    		//---------------------------------------------
     
     
     
    			//------------------------------
    		    btnOk = new JButton("ok");
    		    btnOk.addActionListener(new ButtonListener());
         		btnOk.setBounds(507, 7, 53, 23);
    			panel.add(btnOk);
     
     
     
     
     
     
    	  }
     
     
    		class ButtonListener implements ActionListener {
    						  ButtonListener() {
    						  }
     
    						  public void actionPerformed(ActionEvent e) {
     
    						      System.out.println("clicked  :" + click +"times ");
    						      click++;
     
    						           JPanel  panel_1 = new JPanel();
    								        panel_1.setBorder(new BevelBorder(BevelBorder.LOWERED, new Color(50, 205, 50), null, new Color(50, 205, 50), null));
    										panel_1.setBounds(10, 58, 570, 180);	
    										contentPane.add(panel_1);
    										panel_1.setLayout(null);
    										panel_1.setVisible(true);
     
     
    										JButton btnAjouter = new JButton("Ajouter");
    										btnAjouter.setBounds(109, 146, 89, 23);
    										panel_1.add(btnAjouter);
     
    										JButton btnSupprimer = new JButton("Supprimer");
    										btnSupprimer.setBounds(224, 146, 99, 23);
    										panel_1.add(btnSupprimer);
     
     
     
    								        String   filSel = comboFiliere.getSelectedItem().toString();
    								    	String  levSel = comboLevel.getSelectedItem().toString();
    									    String  yearSel = yearChooser.getYear()+"";
     
    									System.out.println("filiere " +filSel );
    									System.out.println("level " + levSel);
    									System.out.println("year "+ yearSel);
     
    									 modelEtudiant = new TableModelEtudiantFly(filSel,levSel,yearSel);
    									 tableGE = new JTable(modelEtudiant);
    									 JScrollPane scrollPaneGE = new JScrollPane(tableGE);
    									 scrollPaneGE.setBounds(42, 11, 468, 115);
    								 	 panel_1.add(scrollPaneGE);
     
     
    								 	tableGE.addMouseListener(new Mouselistner()); 
     
    						  }
     
     
     
    						   }
     
     
     
     
    		class Mouselistner implements MouseListener{
     
    			public Mouselistner() {
    				// TODO Auto-generated constructor stub
    				System.out.println("row count from mousListner : " + tableGE.getRowCount());
     
    			}
     
    			@Override
    			public void mouseClicked(MouseEvent evt) {
    				System.out.println("Mouse clicked");
     
     
     
    				System.out.println("Ligne :" + tableGE.getSelectedRow());
    	        	rowSelected = tableGE.getSelectedRow();
    	        	System.out.println("Colonne :" + tableGE.getSelectedColumn());
     
     
    			            System.out.println(modelEtudiant.getEtudiant(rowSelected));
    			        	   etudiantSelected = modelEtudiant.getEtudiant(rowSelected);
     
    			        	if (evt.getClickCount() == 3) {
    			        	      System.out.println("triple-click");
    			        	    } 
    			        	else if (evt.getClickCount() == 2) {
     
    			        	      System.out.println("double-click");
     
    			        	      new FicheEtudiant(etudiantSelected).setVisible(true);
     
    			            }
     
     
    			        	etudiantSelected = new Etudiant();
    			        	rowSelected = 0;
     
     
     
    		 	}
     
    			@Override
    			public void mouseEntered(MouseEvent e) {
    				// TODO Auto-generated method stub
     
    			}
     
    			@Override
    			public void mouseExited(MouseEvent e) {
    				// TODO Auto-generated method stub
     
    			}
     
    			@Override
    			public void mousePressed(MouseEvent e) {
    				// TODO Auto-generated method stub
     
    			}
     
    			@Override
    			public void mouseReleased(MouseEvent e) {
    				// TODO Auto-generated method stub
     
    			}
     
     
    		}
     
    }
    et mon model
    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
     
    package ma.ismp.gpedagogique.presentation;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import javax.swing.table.AbstractTableModel;
     
    import ma.ismp.gpedagogique.application.EtudiantServiceFactory;
    import ma.ismp.gpedagogique.domain.model.Etudiant;
     
    public class TableModelEtudiantFly extends AbstractTableModel {
     
     
     
    	public  EtudiantServiceFactory esf = new EtudiantServiceFactory();
     
    	public List<Etudiant> studentList ;
    	//= esf.getEtudiantListByFLY(etudiantFiliere, etudiantLevel, etudiantYear)
    	public  Object [] colnames = {"Matricule", "Nom", "Prénom" , "Nationalité" ,"Filière","Niveau" };
    	private List<Etudiant> etudiantList;  
     
    	private String f;
    	private String l;
    	private String y;
     
     
     
    	 public TableModelEtudiantFly(String f,String l,String y){
     
    		 this.f =f;
    		 this.l =l;
    		 this.y =y;
     
    		 System.out.println("from ModelFLY: "+ f+"   "+l + "   "+y);
    		 studentList = esf.getEtudiantListByFLY(f, l, y);
    		 System.out.println("studentList from model(params) :" + studentList);
     
    		 etudiantList = new ArrayList<Etudiant>();
    		 etudiantList.clear();
    	       for(int i=0;i<studentList.size();i++)
    				     {
     
    	    	             etudiantList.add(studentList.get(i));
     
    				     }
    	       System.out.println("loading model(params) ..."); 
    	       studentList.clear();
                 }
     
     
     
    	 @Override
    		public int getColumnCount() {
    			// TODO Auto-generated method stub
    			return colnames.length;
    		}
     
     
    		@Override
    		public int getRowCount() {
     
    			System.out.println("rowcount from model :" + etudiantList.size() );
    			 return etudiantList.size();
    		}
     
     
    				@Override
    				public Object getValueAt(int rowIndex, int columnIndex) {
     
     
    					switch(columnIndex){
    					case 0:
    						return etudiantList.get(rowIndex).getEtudiantMatricule();
    					case 1:
    						return etudiantList.get(rowIndex).getEtudiantNom();
    					case 2:
    						return etudiantList.get(rowIndex).getEtudiantPrenom();
    					case 3:
    						return etudiantList.get(rowIndex).getEtudiantNationalite();
    					case 4:
    						return etudiantList.get(rowIndex).getEtudiantFiliere();
    					case 5:
    						return etudiantList.get(rowIndex).getEtudiantLevel();
    					default:
    						return null; //Ne devrait jamais arriver
     
    					}
     
     
     
     
    				}
     
     
    		   public String getColumnName(int col) {
    		        return (String) colnames[col];
    		    }
     
     
     
    		   public  Etudiant getEtudiant(int rowIndex)
    		   {  System.out.println("etudiantList from getEtudiant :" +etudiantList);
     
    			   Etudiant e = etudiantList.get(rowIndex);
    			 //   System.out.println(e);
     
    			   return e;
    		   }
     
     
    	}
    tout aide et conseil est le bienvenu ,Merci

  6. #6
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    	        	rowSelected = tableGE.getSelectedRow();
    	        	System.out.println("Colonne:" + tableGE.getSelectedColumn());
     
    	            System.out.println(modelEtudiant.getEtudiant(rowSelected));
    	        	   etudiantSelected = modelEtudiant.getEtudiant(rowSelected);
    Et à ton avis, il se passe quoi avec ce bout de code quand on a pas de row sélectionné?
    rowSelected vaut alors -1 et forcément, dur dur e récupérer l'étudiant -1.

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

Discussions similaires

  1. Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    Par Trint dans le forum Interfaces Graphiques en Java
    Réponses: 6
    Dernier message: 27/02/2007, 11h28
  2. [Debutante] erreur Exception in thread "AWT-EventQueue-0"
    Par mariafan dans le forum AWT/Swing
    Réponses: 16
    Dernier message: 01/02/2007, 14h38
  3. [Impression] Exception in thread "AWT-EventQueue-0"
    Par philippe13 dans le forum AWT/Swing
    Réponses: 7
    Dernier message: 07/09/2006, 16h26
  4. Réponses: 8
    Dernier message: 11/05/2006, 19h32
  5. [JDIC]Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    Par kedare dans le forum Concurrence et multi-thread
    Réponses: 4
    Dernier message: 06/05/2006, 22h45

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