Dividing up the Drawing Area

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
Historical topic: Java appletsModern web browsers do not run Java applets. The Applet API was deprecated for removal before Java 25 and was removed in Java 26. Treat applet examples on this page as historical object-oriented/GUI examples; for new desktop interfaces use Swing where appropriate or JavaFX/OpenJFX.

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?

Answer:

300/10

Dividing up the Drawing Area

That was an easy question, but an important one, conceptually. Now we need to determine how to draw a cricle inside each square.

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

ten circles

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)

Say that each circle will completely fill its square. Then each circle has a width and height of 300/10.

QUESTION 12:

What is the radius of each circle?

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