This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have tried wrting this program using JFrames and plain old applets. I get the same results every time - it wont repaint when I call it. I put some debugging info in it and I can tell that it is doing what it is supposed to other than repaint(). It is supposed to loop through animations in response to arrow key input and repaint every time. However, repaint only gets called once at the end of the "cylce" of images stored in the array. The code is stripped down to barebones - can someone please proveide some insight? I have been slamming my head against a wall for hours on this one. I am sure there is some extra stuff in there as I stripped it down for clarity. I have tried a lot of things and they all yield the exact same result. Thank you.
Thanks for the quick responses. Unfortunately, I didnt really understand what to do with them. I read through the tutorial and I tried to add a super.updateComponent call in the right spot... It doesnt even compile (something about not recognizing what updateComponent is) - but that is what happens when I dont know why I am doing something. I dont know much about Swing in the first place. I first wrote a plain old applet for this but I converted it to see if I could get different behavior. If you compile and run my code it does paint fine when it actually invokes the paint method. On line 51, the repaint() is ignored repeatedly. It executed the loop but ignores the call to repaint. I have read that repaint() calls can be ignored but I know nothing about it and this seems to be what is happening. Is overriding paint just bad style or would it cause any of my problems. The applet does paint - it just ignores the repaints that are in while loops - otherwise known as the animation of the program. Thanks again.
Joined: Jun 13, 2009
I tried to add a super.updateComponent call in the right spot
No where has anybody suggested that you add "super.updateComponent()" in your code. Read the suggestions and don't make up code.
Is overriding paint just bad style or would it cause any of my problems.
It is bad style and will potentially cause problems if done incorrectly. You have implemented it incorrectly and are having problems.
You where given a link to the Swing tutorial that contains working example. If you can't understand the working examples I'm not sure how you expect us to help because we can't write the code for you. If you don't understand something from the tutorial then you need to ask a specific question.
The tutorial also has a section on "How to Use Swing Timers" which can help you out.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com