Flickering occurs when Active Rendering with JPanel, not sure why as I've done this before (couldn't find source code of that project however).
Relevant Code:
Graphics g = projectDCWindow.getWindowGraphics(); // Gets the Graphics Object from a JFrame
g.setColor(Color.BLACK);
g.fillRect(0, 0, (int) ProjectDCInfo.getDefaultWindowSize().getWidth(), (int) ProjectDCInfo.getDefaultWindowSize().getHeight()); // Clears the screen
projectDCGSM.get().render(g); // Game State Manager which simply draws to the Graphics Object
g.dispose();
This is where I draw to the Graphics Object, drawX and drawY are being updated
g.setColor(Color.BLUE);
g.fillRect(drawX, drawY, 100, 200);
The JFrame Code
private JFrame projectDCWindow;
protected ProjectDCWindow()
{
projectDCWindow = new JFrame(WINDOW_TITLE);
projectDCWindow.setPreferredSize(getDefaultWindowSize());
projectDCWindow.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
projectDCWindow.addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
ProjectDC.getInstance().requestClose();
}
});
projectDCWindow.addComponentListener(new ComponentAdapter()
{
@Override
public void componentResized(ComponentEvent e)
{
onResize(projectDCWindow.getWidth(), projectDCWindow.getHeight());
}
});
projectDCWindow.pack();
projectDCWindow.setLocationRelativeTo(null);
projectDCWindow.setVisible(true);
}
private void onResize(int newWidth, int newHeight)
{
ProjectDCInfo.setWindowSize(newWidth, newHeight);
}
public Graphics getWindowGraphics()
{
return projectDCWindow.getGraphics();
}