Centering a Circle

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.

Answer:

A circle.

Centering a Circle

Picture of a Circle

To center the circle in the applet's area think in terms of the square that contains it. Put the square's center at the center of the drawing area. If the width and height of the drawing area is 150 by 150, then the square's upper left corner should be put at:

X = (150/2 - radius)

Y = (150/2 - radius)

Similar calculations are needed to center other figures, or when you want to put a figure at some place other than the center of the drawing area.

QUESTION 15:

Say that you want a circle of radius 50 centered on the point (100, 300). What should the drawOval() command look like?

drawOval( , , ,  )