Move the rectangle around the screen at a 45-degree angle.
Called by the Thread when there is CPU time available for me.
// Get the framesize
int width = getSize().width;
int height = getSize().height;
// Start at a random location in it.
x = (int)(Math.random() * width);
y = (int)(Math.random() * height);
while (!done) {
// Obtain current size, in case resized.
width = getSize().width;
height = getSize().height;
// Did we go off the deep end? :-)
if (x++ >= width)
x=0; // return to shallow end
if (y++ >= height)
y=0;
repaint(); // Tell AWT to call our paint().
try {
Thread.sleep(250);
} catch (InterruptedException e) {
return;
}
}