Skip to main content

Posts

Showing posts with the label doublebuffered

Why is getSize() not working for me here and why the flicker when resizing?

This is my first attempt at using BufferStrategy and I'd really appreciate some hints. 1) Why, in the below code, does getSize() return dimensions of 0 until you have resized the window? How can I detect the size of the window right away? 2) Why when getSize() is returning something is it not the full dimensions of the window? IE why is there a blackless strip to the bottom and right? 3) Is there a way to get rid of the flicker when you resize the window? import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferStrategy; import javax.swing.JFrame; import javax.swing.JPanel; public class BSTest extends JFrame { BufferStrategy bs; DrawPanel panel = new DrawPanel(); public BSTest() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(800,420); setLocationRelativeTo(null); setIgnoreRepaint(true); setVisible(true); createBufferStrategy(2); bs = getBufferStrategy(); panel.set