i've made this little game but the image keeps on flickering. i've read about double buffering online, but i really don't know how to implement the code into my game. here's some of the source code from the constructor and paint method:
public Game(){
super("test");
setSize(495,429);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
try{
img = ImageIO.read(new File("background.png"));
}
catch (IOException e){
}
start1 = new MovePlayer();
start2 = new MoveEnemy();
start2.start();
start1.start();
addKeyListener(new ButtonListener1());
}//close constructor
public void paint(Graphics g){
super.paint(g);
g.setColor(Color.RED);
g.fillRect(player.x,player.y,player.width,player.height);//player
g.setColor(Color.BLACK);
g.fillRect(enemy.x,enemy.y,enemy.width,enemy.height);//enemy
g.drawImage(img, 0 - focusX, 0 - focusY, this);//background image
}//close paint
i understand the concept of double buffering, but i need help on how to implement it for my case.
i've tried following this code http://www.realapplets.com/tutorial/DoubleBuffering.html but it seems that it only clears the rectangle and not an image like i need.