I guess you dont see it was not compiling and then you use an older version of your compiled class file
you just mispelled ballYPosition => you use severals time ballYPostion
also you mispelled destroy method of the Applet
corrected code here :
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
public class BallApplet extends Applet implements Runnable {
private static final long serialVersionUID = -7570390841627016661L;
private int ballXPosition = 10;
private int ballYPosition = 100;
private int ballRadius = 20;
private int ballXSpeed;
private int ballYSpeed;
private Image dbImage; //an image to use for double buffering
private Graphics dbGraphics;
public void init() {
}
public void start() {
Thread myThread = new Thread(this);
myThread.start();
}
public void stop() {
}
public void destory() {
}
public void run() {
//lowering the threads priority
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
//loop to constantly repaint the screen
while(true) {
/* Collision detections between the ball and all four walls*/
if(ballXPosition > this.getWidth() - ballRadius) {
//change the direction
ballXSpeed = -1;
}
else if(ballXPosition < ballRadius) {
//change the direction
ballXSpeed = 1;
}
if(ballYPosition > this.getHeight() - ballRadius) {
ballYSpeed = -1;
}
else if(ballYPosition < ballRadius) {
ballYSpeed = 1;
}
ballXPosition += ballXSpeed;
ballYPosition += ballYSpeed;
//repaint
repaint();
try {
//try to stop the thread for 20 ms
Thread.sleep(20);
} catch (InterruptedException ex) {
//do nothing here if we cant
}
//making the priority max again
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
}
}
public void paint(Graphics g) {
//set the paint color
g.setColor(Color.BLUE);
//draw a circle
g.fillOval(ballXPosition - ballRadius, ballYPosition - ballRadius,
ballRadius * 2, ballRadius * 2);
}
public void update(Graphics g) {
//create the buffered image
if (dbImage == null) {
dbImage = createImage(this.getSize().width, this.getSize().height);
dbGraphics = dbImage.getGraphics();
}
//clear background
dbGraphics.setColor(getBackground());
dbGraphics.fillRect(0, 0, this.getSize().width, this.getSize().height);
//draw background
dbGraphics.setColor(getForeground());
paint(dbGraphics);
//finally draw this buffered image to the actual screen
g.drawImage(dbImage, 0, 0, this);
}
}