Several Circle Objects

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:

More Circle objects could be constructed in the applet, and their draw() methods called.

Several Circle Objects

The suggested answer is one way to do it. (Another way will be used in a few pages.) Here is the applet, modified to draw three concentric circles:

// assume that the drawing area is 200 by 200
public class TestCircle3 extends JApplet
{
  Circle circ1 = new Circle( 100, 100, 10 );
  Circle circ2 = new Circle( 100, 100, 20 );
  Circle circ3 = new Circle( 100, 100, 30 );
  
  public void paint ( Graphics gr )
  { 
    circ1.draw( gr );    
    circ2.draw( gr );    
    circ3.draw( gr );    
  }
}

Here is what it draws:


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

Notice that with the Circle object it was much easier to draw concentric circles than using drawOval() directly.

Although the present definition of the Circle class is useful, it needs more work if it is to be used as a drawing tool.

QUESTION 8:

What (in general) needs to be done to a Circle object so that it will draw another circle in another location?