Can several JPanels be instanced in a loop, in the same manner as JLabels can?
Originally posted by Henry Wong:
In this case, as stated by the error message, your variable i is out of scope.
As said, I am not sure why compiler takes exception to this, as with program FT, the same syntax ie: new FT().buildGUI(); compiled and ran okay -
FT2 does compile and run - but only generates a gui of one panel - not the full six panel gui that I wanted to get.
The line 66 in FT2 seems to correspond with the line :-
- but I don't think that is the line compiler is referring to...
so, the i of
label[i] = new JLabel(images);
has to include the value of j (to go from 7 to < 42)
you only need a single System.out.println() in the loop
print out '7' (i = 0, j = 1)
print out '8' (i = 1, j = 1)
print out '14' (i = 0, j = 2)
do you see a relationship in the above?
The line appears to be
[Campbell@queeg applications]$ javac FT3.java
[Campbell@queeg applications]$ java FT3
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2