So I normally use a JPanel when I want to do some custom drawing (games not just UI)
The JPanel sometimes gives a strange jitter just on certain images being draw which is why I thought maybe it was not being double buffered or it was doing a bad version of double buffering. So I try canvas and well the jitter is gone but it is slow. ???
I have tried using a canvas with double buffering and it runs at 1/3 the speed of my JPanel version.
The canvas code
public void render()
{
long startTime = System.currentTimeMillis();
g.setColor(Color.BLACK);
g.fillRect(0,0,frame.getWidth(),frame.getHeight());
g.setColor(Color.yellow);
g.drawString("FPS: " + fps, 15, 15);
long endTime = System.currentTimeMillis();
g.drawString("Time Render: " + (endTime-startTime) + "ms", 15, 60);
g.dispose();
bufferstrat.show();
}
The JPanel Code
public void paintComponent(Graphics g)
{
long startTime = System.currentTimeMillis();
g.drawString("FPS: " + fps, 15, 15);
long endTime = System.currentTimeMillis();
g.drawString("Time Render: " + (endTime-startTime) + "ms", 15, 60);
g.dispose();
System.out.println(pane.isDoubleBuffered());
}
The JPanel Is indeed double buffered.
What gives? Am I doing something wrong?
I have to be doing something wrong but everything is setup the exact same. If anything, the JPanel code is more ugly.