Search code examples
javaswinggraphicsbufferstrategy

What happens when I call "BufferStrategy.show()"?


Graphics g = bs.getDrawGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, getWidth(), getHeight());
g.dispose();
bs.show();

Does calling bs.show() actually display the buffered frames? If so, how? It simply says that it makes the next available buffer visible, but how about current buffer? When does it get displayed?


Solution

  • According the documentation:

    Makes the next available buffer visible by either copying the memory (blitting) or changing the display pointer (flipping).

    Simply said it means the BufferStrategy becomes the current buffer for the JFrame.