Hello,
I wanted to use for loop to create new labels and used this
for (int i = 0; i < 4; i++) {
JLabel label[i] = new JLabel("label " + i);
}
but I get the error
Type mismatch: cannot convert from JLabel to JLabel[]
Any help would be appreciated
Printable View
Hello,
I wanted to use for loop to create new labels and used this
for (int i = 0; i < 4; i++) {
JLabel label[i] = new JLabel("label " + i);
}
but I get the error
Type mismatch: cannot convert from JLabel to JLabel[]
Any help would be appreciated
Believe the error message as it's correct. It's telling you that this class doesn't have an image(...) method that takes an int for a parameter. So what is this image method? Or do you instead mean to use an array named image?
Fubarable--I edited the posting since my initial one, I am trying to create four labels using a loop. Thank you.
Quoting so my answers make sense and stay in sync with your questions --
@nome: you've got to show more code. I don't know how we can be expected to guess what's wrong based on this limited amount of data. How much code, I don't know as that's where the art of asking a question comes into play. Not too much or no one will take the time to read it, but not a few scant lines either. For instance, where do you declare your array? Is it a 2-dimensional array (which I'm betting it is)?
@Fubarable
I solved it. THis is what I was trying to do.
for (int i = 0; i < 4; i++) {
JLabel label = new JLabel("label" + i);
label.setName("label" + (i));
}
THanks for your replies:(grin)::(handshake):