The applet's drawing area is 300 pixels wide. If there are to be 10 circles, how wide is the area which will be used for each circle?

Eine gute Antwort wäre:


Dividing up the Drawing Area

That was an easy question, but an important one, conceptually. The problem we have to solve is now (almost): "How do you draw a circle inside a square?" We know the answer to that.

Here is a picture of the situation. There are 10 squares lined up along the horizontal center. Each square contains a red circle.

The lines are for visualization. They are not in the final picture. A call to drawOval() with approriate parameters draws each circle. If the total width of the picture is 300, then the left edges of the squares are at:

X=0, 300/10, 2*(300/10), 3*(300/10), . . . . 9*(300/10)

We have not yet decided how big the circles are to be. Let us say that they are to completely fill each of the ten squares, so that each circle will have a "width" and "height" of 300/10.


The drawing area has a height of 150. What is the Y coordinate of the top of all the squares?