Here comes some dummy explanation, which I would've needed at my beginnings..
You can compare the graphic stuff of the game excellently to a flip-book..
First we have to create a digital flip-book
, which will display our game gfx: use a JPanel or Canvas for this.
Now we say, that we always use 2 pages of the flip-book at the same time:
One that the video game player is seeing on the screen and the one behind it, that is invisible as long as we draw all the bullets, explosions, ... on it. It would really look strange if the player would see how all the effects are drawn on the screen
strategy = getBufferStrategy();
Now we create a Graphics2D object, which we can draw on. This is our invisible next page.
By calling g.drawXXX
you can draw shapes and images on it..
Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
When we finished drawing, we release all the used resources, by finishing the flip-book page
Finally, we show the next page of our flip-book to the player(the one that we have been drawing on) and everything starts from the beginning.