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.
ive been working on a project, that requires heavy use of java 2d graphics. My code is probably infact 6000 lines. There is the need fora hell of alot of IF ELSE statements in the graphics method. The performace of my application is absolutley shocking. The application seems to take alot of system resources. For example, just dragging the JFRAME window along the desktop will reult in the frame moving in slow motion. And performace in the application is not great either. Everything seems to be so slow. I have also tried runign the application telling java to use more system memory using the Xms command. Does anybody have any suggestions for a possible solution to this problem?
It's hard to say without knowing how your application works. Swing uses the graphics2d API extensivly and there are not any issues with that. So I can't imagine it being a graphics2d API issue. More likely it is how you have implemented it. But like I said, you have not really provided enough information to determine that.
I realise you probably don't want to post your 6000 lines of code, but the other option might be to break down 1 part of your app into it's own smaller application that you could post so we could see how you have done things and test the code for you.
Gotta be implementation.. I'm doing some pretty heavy swing here at work (well more than 6000 lines) and things run pretty slick..
If I were a betting man, I'd say your using a heck of a lot of listeners, or really expensive listeners? That'll slow down the UI like nobodies business. You have to be kinda careful in larger clients when your using them, especially if you end up with listeners hanging around when they shouldn't be or if listeners are trying to do to much. [ February 09, 2005: Message edited by: Alexander Rudloff ]
In your posting you mention that you have a lot of if else statements in your graphics (paint) method. Sounds like you're trying to do some custom rendering, what are you trying to render? Do you also have a lot of time consuming looping going on and/or some time consuming calls within loops. You need to keep your repaint time down to a minimum and only call repaint when necessary. Sounds to me like you're doing too much computing logic in your paint method. You should only paint whatever needs to be rendered, when it needs to be rendered and only repaint the part of the screen that needs repainting. What's more, you should not have many if else statements in your paint method, objects should know how to render themselves. Seems to me you should also try to apply the model view controller pattern and separate your model and control code from your view code. I'd have to see your code to give a more accurate diagnosis, right now I'm half guessing at your problem. If you could tell me what you're trying to render, I may be able to give better advice. I hope this helps.
Don't guess (you'll probably be wrong!). Run your app through a profiler and find out where the time is being taken. JProfiler has a free 10 day trial you can use or if you're using netbeans you can use JFluid for free.
Joined: Jan 21, 2005
thanks for the reply every one. I could perhaps email the code, to demostarate what im doing?
Joined: Jan 21, 2005
also how do i go abouts only painting a certain area of the screen? Im afraid I have not had much experience with java 2d graphics.
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