Original Post
hi, i am trying to program a java applet game, and it keeps flickering. i was told that it was double buffering, i cant seem to get it to work. if anyone can help me out that would be awsome. code
import java.applet.*;
import java.awt.*;
import java.net.*;
public class Threads1 extends Applet implements Runnable {
Image pic;
URL base;
MediaTracker mt;
int width, height;
int i = 200;
Thread t = null;
boolean threadSuspended;
public void init() {
mt = new MediaTracker(this);
try {
base = getDocumentBase();
}
catch (Exception e) {}
pic = getImage(base,"FFRJ/start.gif");
try {
mt.waitForAll();
}
catch (InterruptedException e) {}
width = getSize().width;
height = getSize().height;
setBackground( Color.black );
}
public void destroy() {
System.out.println("destroy()");
}
public void start() {
if ( t == null ) {
t = new Thread( this );
threadSuspended = false;
t.start();
}
else {
if ( threadSuspended ) {
threadSuspended = false;
synchronized( this ) {
notify();
}
}
}
}
public void stop() {
threadSuspended = true;
}
public void run() {
try {
while (true) {
if(i<=-100)
i=300;
i-=5;
if ( i == 10 ) {
i = 0;
}
showStatus( "i is " + i );
if ( threadSuspended ) {
synchronized( this ) {
while ( threadSuspended ) {
wait();
}
}
}
repaint();
t.sleep( 10 );
}
}
catch (InterruptedException e) { }
}
public void paint( Graphics g ) {
g.setColor( Color.green );
g.drawImage(pic,20,i,this);
g.drawRect( 10, i, 100, 15 );
}
}