Yes the loop is just a delay. Otherwise the applet would just be a blur. you have to adjust the count depending on how fast your computer is.

also this doesn't work
int x,y,X,Y;
you get the error variable may not have been initialized.
however, I believe that if you used the variable outside all the for loops, you wouldn't get an error.

you could do this though
int x=0,y=0,X=0,Y=0;