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
|
............
Container contenu = getContentPane();
...........
for (int y = 0; y < 5; y++) {
for (int i = 0; i < 5; i++) {
grid[y][i] = new JLabel(new ImageIcon("image1.jpg" ));
contenu.add(grid[y][i]);
grid[y][i].addMouseListener(this);
System.out.println(y + " " + i);
}
}
}
public void mouseClicked(MouseEvent ev)
{
Object source = ev.getSource();
if (source == grid[2][2]) { //ou grid[x][y]
//ce que je voudrais
grid[2][2] = new JLabel(new ImageIcon("image2.jpg" ));
grid[3][3] = new JLabel(new ImageIcon("image2.jpg" ));
etc.... |