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

[1533 byte] By [Yuushia] at [2007-10-2 23:19:37]
# 1
This has nothing to do with the event listener at all and everything to do with the variable you keep resetting.If JLabel licon was declared in the scope of the for loop this problem would go away.
Yuushia at 2007-7-14 15:57:03 > top of Java-index,Java Essentials,New To Java...
# 2
I know that but then I have no clue how to add the array's with info onto the labels.
Yuushia at 2007-7-14 15:57:03 > top of Java-index,Java Essentials,New To Java...