BufferedStrategy need info

I have some general questions about the bufferedstrategy class and how I can use them and hope you can help.

a) Since I use the graphicscontext (graphics2d g) to draw, do I have to clear the screen for every iteration of my gameloop to avoid duplicates? If I have a map with a box, if I don’t clear it and the box moves during one iteration, will I draw two boxes or is the image automatically cleared for me?

b) Depending on the above, if the image is automatically cleared, do I have to redraw EVERYTHING in every iteration of the gameloop? This seems a bit inefficient (imagine the player going afk for 30 minutes, I am still rendering at full speed, the same static objects).

c) I am currently attaching a bufferedstrategy to a canvas, this canvas can have a gazillion subcomponents. Do I have to render each and every component (how?) or does the canvas have a paint-method that paints all of its components? How would one actively render a components image?

  1. Yes, or else yes, you will be drawing multiple boxes(I believe). Basically, in any sort of graphical program, you need to clear the screen constantly. You will also want to limit rendering so that even on slower machines, objects won’t render faster and thus appear to be faster.
  2. You only need to draw anything that is currently on the screen and is visible. I believe you also can optimize your game a little by only re-drawing objects that have actually moved on screen. But that may not work, and it may not apply to you. Just something to look into!
  3. I don’t honestly understand what you’re asking here, could you elaborate or provide an example?

Thank you for the quick answer.

On your answer to the second question, thank you, for now I think I will simply empty(clear) the screen and redraw. As to avoiding redrawing things that haven’t changed, how would that be possible if I clear? Do I have to selectively clear? (Eg if only a box has moved, just clear area big enough to draw something on where box was and where box will be and draw to this area on next iteration) Is this feasible?

On the third question. I was wondering how I actively render things that are attached to the canvas, like a JButton or a Menulayout, do I have to call their paint? (which seems passive).