- Your
paintComponent(...)
method needs to call the super method, probably as the first method call inside of it's body:super.paintComponent(g)'
. This will clear any images drawn previously. This is your main problem. - You shouldn't have sleeps or pauses in your Swing program like you're doing as this will break as soon as you move that code out of main. Instead use a Swing Timer for your animation.
e.g.,
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g); // ****** be sure to add this ******
nextlevel(h,w);
g.drawImage(image,x,y,wp,hp,null);
}