If you don't need Accelerated Graphics, you can draw onto a BufferedImage
with Graphics2D
. Once you have your data in the BufferedImage
, you can simply paint the BufferedImage
onto the component. This will avoid any sort of flickering you are talking about.
Creating the BufferedImage is easy:
int w = 800;
int h = 600;
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Then you can draw objects onto it with a graphics context (Possibly in your own render function):
Graphics2D g = bi.createGraphics();
g.drawImage(img, 0, 0, null);
//img could be your sprites, or whatever you'd like
g.dipose();//Courtesy of MadProgrammer
//You own this graphics context, therefore you should dispose of it.
Then when you repaint your component, you draw the BufferedImage onto it as one piece:
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawImage(bi, 0, 0, null);
}
Its sort of like using BufferedImage as a back buffer, and then once you are done drawing to it, you repaint it onto the component.