I wonder that how the function below is working. With the first function call, it paints only background over the old square location, but the with second function call it paints red square.
if(CURR_X != x || CURR_Y != y) {
//The square is moving, repaint backgorund
//over the old square location
repaint(CURR_X,CURR_Y,CURR_W+OFFSET,CURR_H+OFFSET);
//Update coordinates
square.setX(x);
square.setY(y);
repaint(square.getX(),square.getY(),
square.getWidth()+OFFSET,square.getHeight()+OFFSET);
}