aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes java 2d performance issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "java 2d performance issue" Watch "java 2d performance issue" New topic
Author

java 2d performance issue

alun groome
Greenhorn

Joined: Jan 21, 2005
Posts: 21
Hi,

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?

Thanks in advance
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Alexander Rudloff
Greenhorn

Joined: Jan 11, 2005
Posts: 14
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 ]

Certs: SCJP 1.4, RUP
Art Contreras
Greenhorn

Joined: Feb 10, 2005
Posts: 1
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 Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
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.

D.
alun groome
Greenhorn

Joined: Jan 21, 2005
Posts: 21
thanks for the reply every one. I could perhaps email the code, to demostarate what im doing?

thanks again
alun groome
Greenhorn

Joined: Jan 21, 2005
Posts: 21
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.

thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java 2d performance issue