PaintComponent method

I have a very fast question for you guys. I was going to go look at this on the Java site and docs but it seems to be down for me.

I have been looking at the FPS in my game and trying to see how well it goes, etc. I am getting 20 FPS with a swing GUI system [subclassed jlabel and do my drawing on that]. I thought that this was pretty slow, so its time to figure out why its taking so long. So to start off first, I removed all of the functionality from my paintComponent method except for the FPS calcuations. When I ran this new modification, my FPS went up by 1. This could be good or it could be bad. Good as in what I am doing for the game is not really processor heavy :slight_smile: Bad: It seems that the call to this method is done 20 times a second. I was going to try and lock it at between 30 or 50 but since it’s locked at 20 then…I suppose its ok.

Anyways - my question is: does swing call paint component methods at regular intervals? I’m sure this is on the docs but I can’t get to them.

Thanks!

EDIT: My draw function takes between 0 - 45 MS to draw, with about +75% of them being 15/16 MS.

PS: Are there any good sites that have some information regarding the opengl pipeline for java? I haven’t looked around much (haven’t googled either but will after this post).

Hi,

No, it only does so when there’s a ‘dirty’ area to repaint which was covered by a window and now is visible or when user interaction changes something that needs updating.

One reason why you’re FPS might be so low is that you haven’t over-ridden component.update() which repaints the JLabel’s background.

Best regards,
Keith

paintComponent is only invoked when something happens that requires redrawing, such as things being dragged around, text changes, etc.

If you do not somehow manually call repaint(), then there is no explanation why it would have a framerate greater than 0. But how can you observe that the “call is done 20 times a second” without having called something that results in a repaint with that frequency?

I put a counter in the paint method that would increment everytime control entered and after 1 second, I’d display the counter and redo it. So, since it is being entered 20 times a second, I am getting 20 frames drawn. I do all my game drawing in this method. Maybe I have some old code I wrote buried deep down in the bowels of my problem.