Dear all
I am making a program which adds lots of jlabels to a frame (the idea, eventually, is that each jlabel will link to a different program on my dekstop)
The trimmed down code below shows that I have a script which creates an array of multiple jlabels which are appended to the jframe (I eventually got this working). I am now a little stuck and I would really like to know how to add the same method to each jlabel so that, when clicked, a pop up label tells me its position in the array. (e.g. the 7th element)
One idea I have had is to use the "extends" keyword. I believe this is a form of inheritance, so that all my jlabels have a method to respond to a click event. I am not sure how to go about this. I know how to add a click event method for a single label created manually, but not for multiple labels created programatically.
Until recently the only programming I have done is javascript - I am finding the transition a little hard !!
javax.swing.JLabel[] labels = new javax.swing.JLabel[line_count];
for (int i = 0; i < mystrings.length; i++) {
labels[i] = new javax.swing.JLabel("hello"); //fill the array with the jlabels
cp.add(labels[i]); //append the labels to the frame container
pack();
}
Many thanks in advance
Matt