I'm new to java and am working my way through a tutorial but I want to know how to add double buffering to the code below. The tutorial's code doesn't work, so how do you guys do it? (commented code is helpful
// DOUBLE BUFFERING
import java.applet.*;
import java.awt.*;
public class Game2p2 extends Applet implements Runnable
{
int x_pos = 10;
int y_pos = 100;
int radius = 20;
public void init() {}
public void start(){
//define a new thread
Thread th = new Thread(this);
// start this thread
th.start();
}
public void stop() {}
public void destroy(){}
public void run() {
// lower ThreadPriority
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
// run a long while (true) this means in our case 'allways'
while(true){
// repaint the applet
x_pos++;
repaint();
try{
// Stop thread for 20 milliseconds
Thread.sleep(20);
}
catch(InterruptedException ex){
// do nothing
}
// set ThreadPriority to maximum value
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
}
}
public void paint(Graphics g){
// set color
g.setColor(Color.red);
// paint a filled colored circle
g.fillOval(x_pos - radius, y_pos - radius, 2*radius, 2*radius);
}
}
)