Hi all
I've tried to find out which object is behind the JLabel that caused the MouseEvent. I have a code like this.
for(int i = 0; i < annetutKäsikortit.size(); i++) {
URL _kuva = this.getClass().getResource("/kortit/" + annetutKäsikortit.get(i).haeNumero() + "_pieni.png");
käsikortitJLabel.add(new JLabel(new ImageIcon(_kuva)));
käsikortitJLabel.get(i).addMouseListener(hiirenkuuntelija);
omatKortit.add(käsikortitJLabel.get(i));
}
Sorry about that strange language in the code, let me explain. annetutKäsikortit is an ArrayList which contains the objects given by an another class. _kuva is a temporary variable, which contains the image. haeNumero-method returns a String-object. That all works well. käsikortitJLabel is an ArrayList, where I put those JLabels which I created. omatKortit is a JPanel element, where I draw those images. When I click one of those JLabels, I got my hiirenkuuntelija event listener class make what I want. But I can't find out which Kortti-object is under the JLabel which was just clicked. annetutKäsikortit contains the Kortti-objects and käsikortitJLabel contains the JLabels, they are in the same order. So in principle käsikortitJLabel[0] = annetutKäsikortit[0], but in practise it's not. Kortti-object cannot be compared to a JLabel object.
So what I need? I need to know what is the index of the JLabel in the käsikortitJLabel-ArrayList which was just clicked.
If you didn't understand, I can explain more and answer your questions with pleasure.
Thanks
Mikko