Problem with event
Hello all,
I have a slight problem and it's hard for me to explain so please bear with me. This for method puts 2 icons on the screen with a image and a text. Problem is that when I add a actionlistener the instance gets overwritten every time. Causing only the last added event to be traceable.
Is there any way to solve this? maybe it is possible to change the "licon" to licon1, licon2 etc in the forloop?
protectedvoid makeIcons(String[] image, String[] text){
for (int i = 0; i < image.length; i++){
ImageIcon icon =new ImageIcon(image[i]);
licon =new JLabel(text[i],icon, JLabel.CENTER);
//Set the position of the text, relative to the icon:
licon.setVerticalTextPosition(JLabel.BOTTOM);
licon.setHorizontalTextPosition(JLabel.CENTER);
licon.setForeground(Color.white);
licon.setBounds(x, y, 100, 75);
desktop.add(licon,new Integer(Integer.MIN_VALUE));
y+= 80;
//add mouse listener
MouseListener controller =new MouseListener();
licon.addMouseListener(controller);
}
kindest regards,
Yuushi

