Bonjour,

Alors aujourd'hui mon problème est un problème d'itération.
J'ai une fenêtre sur laquelle il y a des JLists et un bouton. Je sélectionne les éléments des JLists que je souhaite et je j'appuie sur le bouton qui va m'ouvrir une nouvelle fenêtre qui affichera le détail de chaque élément sélectionné avec les photos qui correspondent à ces éléments également.
Donc lorsque j'appuie sur le bouton, celui va instancier ma classe qui affiche les détails en lui envoyant un tableau d'entier contenant les IDs des éléments sélectionnés. Lors du chargement de la nouvelle fenêtre, la méthode "displayRealEstates" est appelé. Je vous met la partie qui nous intéresse (elle se trouve dans cette méthode):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
private int housesToCompare[] = null;
private File directory = null;
private File listOfPictures[] = null;
private int clicksOnNext = 0;
private int clicksOnPrevious = 0;
private int iteratorPictures = 0;
private ArrayList<Integer> clicksOnNextArray = new ArrayList<Integer>();  
private ArrayList<Integer> clicksOnPreviousArray = new ArrayList<Integer>();  
private ArrayList<File> directoryArray = new ArrayList<File>();  
private ArrayList<File[]> listOfPicturesArray = new ArrayList<File[]>();
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
 
if(housesToCompare != null) {
			houses = new Houses(dbConnection);
			//for(int i = 0; i < housesToCompare.length; i++) {
			while(iteratorPictures < housesToCompare.length) {	
				resultSet = houses.getHouseInformation(housesToCompare[iteratorPictures]);
				try{
					while(resultSet.next()) {
						toRent = resultSet.getInt("to_rent");
						toSell = resultSet.getInt("to_sell");
						surface = resultSet.getInt("surface");
						priceForBuying = resultSet.getInt("price_for_buying");
						priceForRenting = resultSet.getInt("price_for_renting");
						available = resultSet.getInt("available");
						numberOfRooms = resultSet.getInt("nb_of_rooms");
						dateOfPublication = resultSet.getString("date_of_publication").substring(8, 10) + "/" + 
											resultSet.getString("date_of_publication").substring(5, 7) + "/" + 
											resultSet.getString("date_of_publication").substring(0, 4);
						if(resultSet.getString("date_of_availability") != null)
							dateOfAvailability = resultSet.getString("date_of_availability").substring(8, 10) + "/" + 
											resultSet.getString("date_of_availability").substring(5, 7) + "/" + 
											resultSet.getString("date_of_availability").substring(0, 4);
						realEstateAddress = resultSet.getString("address");
						realEstatePostCode = resultSet.getString("post_code");
						realEstateCity = resultSet.getString("city");
						realEstateCountry = resultSet.getString("country");
						garden = resultSet.getInt("garden");
						gardenSurface = resultSet.getInt("garden_surface");
						fireplace = resultSet.getInt("fireplace");
						barbecue = resultSet.getInt("barbecue");
						floors = resultSet.getInt("floors");
						parking = resultSet.getInt("parking");
						garage = resultSet.getInt("garage");
					}
					resultSet = houses.getHouseOwnerInformation(housesToCompare[iteratorPictures]);
					while(resultSet.next()) {
						name = resultSet.getString("name");
						firstname = resultSet.getString("firstname");
						email = resultSet.getString("email");
						ownerAddress = resultSet.getString("address");
						ownerPostCode = resultSet.getString("post_code");
						ownerCity = resultSet.getString("city");
						ownerCountry = resultSet.getString("country");
						landPhone = resultSet.getString("land_phone");
						if(landPhone == null)
							landPhone = "";
						mobilePhone = resultSet.getString("mobile_phone");
						if(mobilePhone == null)
							mobilePhone = "";
						fax = resultSet.getString("fax");
						if(fax == null)
							fax = "";
					}
				}catch(SQLException e) { e.printStackTrace(); }
				jLabelDescription = new JLabel();
				jLabelDescription.setBounds(new Rectangle(201, y, 485, 115));
				if(toRent == 0) {
					toRentString = "";
					priceForRentingString = "";
					toSellString = "sell";
					priceForBuyingString = priceForBuying.toString() + " €";
				}
				else if(toRent == 1) {
					toRentString = "rent";
					priceForRentingString = priceForRenting.toString() + " €/Month";
					toSellString = "";
					priceForBuyingString = "";
				}
				if(available == 0)
					availableString = ", not available";
				else if(available == 1)
					availableString = ", available from the " + dateOfAvailability;
				if(garden == 0) 
					gardenString = "";
				else if(garden == 1) 
					gardenString = ", garden: " + gardenSurface.toString() + " m<sup>2</sup>";
				if(barbecue == 0)
					barbecueString = "";
				else if (barbecue == 1)
					barbecueString = ", barbecue";
				if(fireplace == 0)
					fireplaceString = "";
				else if (fireplace == 1)
					fireplaceString = ", fireplace";
				if(parking == 0)
					parkingString = "";
				else if(parking == 1)
					parkingString = ", parking";
				if(garage == 0)
					garageString = "";
				else if(garage == 1)
					garageString = ", garage";
				if(!landPhone.equals(""))
						landPhone = ", land phone: " + landPhone;
				if(!mobilePhone.equals(""))
					mobilePhone = ", mobile phone: " + mobilePhone;
				if(!fax.equals(""))
					fax = ", fax: " + fax;
				jLabelDescription.setText("<html>Published on the " + dateOfPublication + "<br><u>House</u> to " + toRentString + toSellString + " for " + 
						priceForBuyingString + priceForRentingString + ". Surface: " + surface.toString() + " m<sup>2</sup>" + availableString +
						", " + numberOfRooms.toString() + " rooms" + gardenString + barbecueString + fireplaceString + ", " + floors.toString() + 
						" floor(s)" + parkingString + garageString + ".<br>Address: " + realEstateAddress + ", " + realEstatePostCode + ", " + 
						realEstateCity + ", " + realEstateCountry + "<br><u>Owner information</u>:<br>" + firstname + " " + name.toUpperCase() + ", " + email + 
						landPhone + mobilePhone + fax + ".<br>Address: " + ownerAddress + ", " + ownerPostCode + ", " + ownerCity + ", " + 
						ownerCountry + "</html>");
				jLabelDescription.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.black, 1));
				jLabelDescription.setVisible(true);
				jLabelImages = new JLabel();
				jLabelImages.setBounds(new Rectangle(1, y, 190, 115));
				jLabelImages.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.black, 1));
				jLabelImages.setVisible(true);
				jButtonPrevious = new JButton();
				jButtonPrevious.setBounds(new Rectangle(75, y + 117, 18, 16));
				jButtonPrevious.setIcon(new ImageIcon(getClass().getClassLoader().getResource("Icons/leftArrow.jpg")));
				jButtonPrevious.setVisible(true);
				jButtonNext = new JButton();
				jButtonNext.setBounds(new Rectangle(95, y + 117, 18, 16));
				jButtonNext.setIcon(new ImageIcon(getClass().getClassLoader().getResource("Icons/rightArrow.jpg")));
				jButtonNext.setVisible(true);
				clicksOnNext = 0;
				clicksOnPrevious = 0;
				directory = new File("Images/Houses/" + housesToCompare[iteratorPictures] + "/");
				directoryArray.add(iteratorPictures, directory);
				if(directoryArray.get(iteratorPictures).exists()) {
					if(directoryArray.get(iteratorPictures).listFiles().length == 0) {
						displayImage(new File("lib/ImageNotAvailable.jpg"));
						jContentPane.updateUI();
					}
					else {
						listOfPictures = new File [directoryArray.get(iteratorPictures).listFiles().length];
						listOfPictures = directoryArray.get(iteratorPictures).listFiles();
						listOfPicturesArray.add(iteratorPictures, listOfPictures);
						displayImage(listOfPicturesArray.get(iteratorPictures)[0]);
						clicksOnNextArray.add(iteratorPictures, clicksOnNext++);
						//imageNumber = clicksOnNext + "/" + listOfPictures.length;
						//jLabelImageNumber.setText(imageNumber);	
						jButtonPrevious.setEnabled(false);
						if(clicksOnNextArray.get(iteratorPictures) >= listOfPicturesArray.get(iteratorPictures).length) 
							jButtonNext.setEnabled(false);
					}
				}
				jButtonPrevious.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						if(directoryArray.get(iteratorPictures).listFiles().length != 0) {
							if(clicksOnNextArray.get(iteratorPictures) > 0) {
								clicksOnNextArray.set(iteratorPictures, clicksOnNext--);
								clicksOnPreviousArray.add(iteratorPictures, clicksOnNextArray.get(iteratorPictures) - 1);
								displayImage(listOfPicturesArray.get(iteratorPictures)[clicksOnPreviousArray.get(iteratorPictures)]);
								//imageNumber = clicksOnNext + "/" + listOfPictures.length;
								//jLabelImageNumber.setText(imageNumber);
								if(clicksOnNextArray.get(iteratorPictures) <= listOfPicturesArray.get(iteratorPictures).length) 			
									jButtonNext.setEnabled(true);
							}
							if(clicksOnNextArray.get(iteratorPictures) == 1) 			
								jButtonPrevious.setEnabled(false);
						}
					}
				});
				jButtonNext.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						if(directoryArray.get(iteratorPictures).listFiles().length != 0) {
							if(clicksOnNextArray.get(iteratorPictures) >= listOfPicturesArray.get(iteratorPictures).length) 
								jButtonNext.setEnabled(false);
							if(!(clicksOnNextArray.get(iteratorPictures) >= listOfPicturesArray.get(iteratorPictures).length)) {
								jButtonPrevious.setEnabled(true);
								displayImage(listOfPicturesArray.get(iteratorPictures)[clicksOnNextArray.get(iteratorPictures)]);
								//imageNumber = clicksOnNext + 1 + "/" + listOfPictures.length;
								//jLabelImageNumber.setText(imageNumber);
								clicksOnNextArray.set(iteratorPictures, clicksOnNext++);
								if(clicksOnNextArray.get(iteratorPictures) >= listOfPicturesArray.get(iteratorPictures).length) 
									jButtonNext.setEnabled(false);
								jContentPane.updateUI();
							}
						}
					}
				});
				iteratorPictures++;
				//}
				jPanel.add(jLabelDescription);
				jPanel.add(jButtonPrevious);
				jPanel.add(jButtonNext);
				jPanel.add(jLabelImages);
				jPanel.updateUI();
				jScrollPane.revalidate();
				y += 136;
			}
		}
Pour chaque élément sélectionné précédemment, je récupère les valeurs (en parcourant le tableau d'entiers reçu en paramètre de mon constructeur) dont j'ai besoin pour afficher les détails via ma base de données. J'affiche ensuite dans un nouveau JLabel ces détails et dans un autre JLabel j'affiche les photos que je récupère grâce à l'ID de l'élément (une des valeurs se trouvant dans le tableau d'entier passé en paramètre au constructeur).
Le problème vient en fait de cette partie (et aussi de l'actionListener d'avant mais comme c'est le même type de problème je ne met que ce passage):
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
jButtonNext.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						if(directoryArray.get(iteratorPictures).listFiles().length != 0) {
							if(clicksOnNextArray.get(iteratorPictures) >= listOfPicturesArray.get(iteratorPictures).length) 
								jButtonNext.setEnabled(false);
							if(!(clicksOnNextArray.get(iteratorPictures) >= listOfPicturesArray.get(iteratorPictures).length)) {
								jButtonPrevious.setEnabled(true);
								displayImage(listOfPicturesArray.get(iteratorPictures)[clicksOnNextArray.get(iteratorPictures)]);
								//imageNumber = clicksOnNext + 1 + "/" + listOfPictures.length;
								//jLabelImageNumber.setText(imageNumber);
								clicksOnNextArray.set(iteratorPictures, clicksOnNext++);
								if(clicksOnNextArray.get(iteratorPictures) >= listOfPicturesArray.get(iteratorPictures).length) 
									jButtonNext.setEnabled(false);
								jContentPane.updateUI();
							}
						}
					}
				});
Le truc c'est que lorsque j'appuie sur le bouton "next" (celui qui a donc cet actionListener) il prend comme valeur la dernière valeur de "iteratorPictures" ce qui me fait une erreur de type "java.lang.IndexOutOfBoundsException".

Donc pour résumer mon problème c'est comment je pourrais faire pour stocker quelque part l'itérateur "iteratorPictures" de chaque élément comme j'ai fait avec des ArrayLists pour les autres variables sachant que l'itérateur de ces ArrayLists était "iteratorPictures" et que là donc il me faut un itérateur pour ll'itérateur "iteratorPictures" ?

Bon même mon résumé est un roman ... Si vous avez du mal à comprendre (c'est fort possible vu mon explication) n'hésitez pas à me le dire et notamment ce que vous ne comprenez pas