Java 2D Paint Components

Hey guys, been lookin around this site for a while, but never posted. Have a question. Currently im in my first year of java at my highschool, so im still a beginner at programming. Question is, is it possible to have 2 paint components on the same frame? what im trying to do is a side scroller type game and i want a static backround picture that doesnt have to repaint. I only need to repaint my player movement. currently, when i currently run the game it slows down alot due to the fact every time i call the repaint method it repaints this backround image that never changes. so im wondering how would i do this in java2d.

no there isn’t a built-in layer system like that. and even if their were, then the UI would be drawing the image over and over as well :wink:

what you need to do is hardware accelerate your background image (actually - every image!). this will greatly improve your performance.

I have written a few examples of this in the past:
http://woogley.net/misc/LayerExample/ - sprite vs layers. in the options menu of that sample app it shows you which examples are “hardware accel”

I’ll try to write a more specific example for you. search around for accelerating java images.

also you might want to try enabling the OpenGL pipeline which uses your videocard to render graphics (assuming the card supports OpenGL)

Thank you very much woogley, very helpful so far. Trying to decode atm, its a lil confusing because we havnt reached into buffered images. . . only thing with graphics we actually hit on was graphics2d so ive been trying to learn bit by bit. Would you mind if i used some of your code in my program im trying?

ok, heres a question, sence ill be adding enemies as i go, wouldnt it be better to just use an arraylist? or is using the Sprite class you have made better? i just figured arraylist would be good because it can hold the corrdinates and it can always change. . . or am i just way off?

ooooo, i think i just got it, ok ill stop updating this post. Thanks very much for the info; def tried the arraylist and got that working (this way i can add enemies as i please and dont have to worry about knowing which space it was in.

Many thanks.