Java allows you to change the size of the window while the program is running. Each time this happens, the Applet runner will invoke your paint method, letting you know that the size of the window has changed. Your program can determine the size of the window by invoking the bounds method. The following code will do the trick:
// get the width and height of the window
Rectangle boundingBox = bounds();
width = boundingBox.width;
height = boundingBox.height;