I have it set inside a class that extends JPanel, and implements Runnable.
I was having trouble with the image flickering, and, upon research, I learned that the repaint() method call is only a request, and may be processed at the CPU's convenience. So I did some more research and I decided to make my own RenderImage method.
The problem is, I'm not getting any errors from it, and yet it won't render to the panel. Both of these methods are called in a run() method once a frame. I'll post the code in question below. Any help is greatly appreciated.
//These are the global variables instantiated in the class outside these methods
public Image dbImage = null;
public Graphics dbg;
public void BufferImage(){
if(dbImage==null){
dbImage = createImage(PWIDTH,PHEIGHT);
dbg = dbImage.getGraphics();
}
//Individual Paint Functions Here
/* These most likely need to check the state first
REMINDER: Implement State Machine before going into all that
*/
dbg.setColor(Color.black);
dbg.fillRect(0,0,PWIDTH,PHEIGHT);
}
public void RenderImage(){
//Draws a pre rendered image of the game to the Panel
Graphics g;
try{
g = this.getGraphics();
if((g!=null)&&(dbImage!=null)){
g.drawImage(dbImage,0,0,this);
}
Toolkit.getDefaultToolkit().sync();
g.dispose();
}catch(Exception e){
System.out.println("Graphics Context Error: " + e);
}
}
Thanks,
Peter