Sorry to bother you all again. I am again having probs with an accursed LED panel thingy. I have finally got it to compile etc - thanks everyone for your help with that (see post here:Non-default constructor problem)! Anyway, I have a method which updates the gifs which are in an LEDPanel:
I am calling the above method 8 times in another class in order to output 8 LED displays. Here's that code:
When i run LEDPanel, i only get one panel displaying. It seems to be the last panel, but i'm not sure! Does anyone know why there is only one LED displaying, and not all 8?
Thanks again all. Celine
We've heard that a million monkeys at a million keyboards would eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true.<br />- Robert Wilensky
i can't really tell from the code fragments, but it looks like you're adding each LEDPanel (twice) and doing some layout stuff in _updateLED:
CODE FRAGMENT... //add the whole panel to the window setLayout( new BorderLayout() ); add( ledPanel ); setBorder( BorderFactory.createEmptyBorder( 20, 20, 20, 20 ) );
Is there another 'shadow' window that you also populate when you invoke main?
if not, it s.b. ok to remove/relocate this code.
My only other comment would be that your _updateLED method also appears to allocate the *same* JLabel set (i'm guessing they are JLabels...) to each panel. As I recall, Swing won't like this. If you continue to have problems, try replacing the .setIcon calls with new JLabel eg
ok celine, i looked at your other post with more of your code and i believe i see what you're asking ...
i think my previous response pretty much still applies: you have a couple of places where you are instantiating some objs you don't use, and the updateLED references LED obj that haven't been properly initialized ...
Last comment would be to check your code to see where you are making changes to the LED visual model - probably only want to do things like layout changes once: at init time etc
i couldn't resist re-organizing your code into one LEDPanel class:
Joined: Nov 22, 2003
You're a lifesaver! I changed "setIcon" to "new JLabel( new ImageIcon..." & took out the panel formatting stuff from the updateLED method as you suggested and it works!!! Makes sense i guess - how can you reset an icon you haven't initialised in the first place. I won't forget this lesson in a hurry!!! Thank you so much for your help & for giving so much of your valuable time to do so.
I have saved the code you posted which is a much more elegant solution to this problem - thanks again. I'm still very much a newbie though & i don't totally understand what's happening there, but i'm gonna spend a bit of time looking at it & running it etc so that i'll understand it by this evening.
Gratefully yours, Celine
Joined: Apr 30, 2004
bravo to you for your hard work and persistence, Celine! i myself learn better by example than by instruction, and so i have benefitted from the wealth of java examples on the web. i'm glad to give back when i can.
thank you for your feedback - 99% of the time i never hear anything so i don't know if i'm helping or harming ... it's nice to hear back, and nicer to have actually helped for a change:-)
Joined: Nov 22, 2003
No need to be modest Clio! I get the feeling you've helped many people before me!!!