The parameters to the fillOval() method are x, y, width, and height, in order. In your code you call it like this -
Here is what this means... The oval is drawn it is drawn 90 pixels from the left side of the applet. The y location is represented by the variable named 'height'. 'height' starts at 70 and decreaes, so the oval starts 70 pixels from the top of the screen and moves up the screen. Width is represented by the variable named 'width', which starts at 180 and increases, so the width of the oval will increase to the right. The height of the oval stays at 180 pixels. The reason the oval seems to be 'increasing' on one side is because you overrode update() to not clear the screen before doing a new paint() call... this isn't good to do without adding double buffering because the draw operations aren't persistant. If anything moves over the applet then it will clear the area that was covered and what you think is being drawn will get messed up.
To actually make the oval increase on all sides around a center point you will need to keep track of both x and y values in addition to width and height. Whenever you increase width you will need to decrease x by half of that amount, and whenever you increase height you will need to decrease y by half of that amount. Since you are using integers and increasing by one, you won't see any change because you can't decrease an integer value by 0.5. You'll need to use decimal values (floats or doubles) to keep track of the x, y, width and height values and use Math.round() to cast them to integers to paint the oval.
Here's your code with the changes (plus using backbuffer, and a main method to test it out without AppletViewer, plus fixes for some of the deprecated stuff you were using... Thread.stop() and size() calls (though you may be using these to stay compatible with JDK 1.1) ) -
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Feb 05, 2003
I also made this work. I'm not sure how, but I was playing around with it. Thanks for the challenge!
-nothing important to say, but learnin' plenty-