Simon
Simon
Can several JPanels be instanced in a loop, in the same manner as JLabels can?
Simon
Simon
Originally posted by Henry Wong:
In this case, as stated by the error message, your variable i is out of scope.
Simon
Simon
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 :-
label[i].addMouseListener(mousie);
- but I don't think that is the line compiler is referring to...
so, the i of
label[i] = new JLabel(images[0]);
has to include the value of j (to go from 7 to < 42)
Simon
Simon
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)
etc.
do you see a relationship in the above?
Simon
Simon
Simon
Simon
Simon
Simon
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
at FT3.buildGUI(FT3.java:33)
at FT3$3.run(FT3.java:97)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
[Campbell@queeg applications]$
Consider Paul's rocket mass heater. |