Smaller Circles

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:

The applet would draw ten circles, as before, but they would be smaller circles.

Smaller Circles

The circles are not side-by-side, and since their left side is touching the left edge of the lines that divide the drawing into 10 regions, the row of circles is shifted left a bit. Here is the modified applet:

import javax.swing.JApplet;
import java.awt.*;

// Assume that the drawing area is 300 by 150.
// Draw ten red circles side-by-side across the drawing area.
public class TenSmallCircles extends JApplet
{
  final int width = 300, height = 150;

  public void paint ( Graphics gr )
  { 
    gr.setColor( Color.red );
    int diameter = 20;
    int Y = height/2 - diameter/2;    // the top edge of the squares

    int count =  0 ;
    while (  count < 10  )
    {
      int X = count*width/10;          // the left edge of each square
      gr.drawOval( X, Y, diameter, diameter );
      count = count + 1; 
    }
  }
}

And here is the pretty picture that it draws on your screen:

Embedded Java applet removed: modern browsers do not support Java applets. The surrounding source code is retained for historical study.

Here is a picture of the situation with the guide lines drawn in:

It would be nice if the circles were all shifted right.

QUESTION 16:

To make the leftmost circle the same distance from the left edge of the drawing as the rightmost circle is from the right edge, what distance should be circles be shifted?