Drawing Method

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:

public Circle( int x, int y, int radius )
{ 
  this.x = x;  this.y = y;  this.radius = radius;
}

Drawing Method

There must be a drawing method. The draw() method will use the Java method:

 
drawOval(int x, int Y, int width, int height)

The method must be told on which drawing area to draw a circle, so the draw method has a single parameter for the Graphics object of the applet.

class Circle
{
  // variables
  int x, y, radius;

  // constructors
  public Circle()
  { 
    x = 0; y = 0; radius = 0; 
  }

  public Circle( int x, int y, int radius )
  { 
    this.x = x;  this.y = y;  this.radius = radius; 
  }

  // methods
  draw( Graphics gr )
  {

    int ulX =  ; // X of upper left corner of rectangle

    int ulY =  ; // Y of upper left corner of rectangle

    gr.drawOval( ulX, ulY, ,  );
  }

}

If you know the center of the circle, (x, y) and radius, you can calculate the coordinates of the upperleft corner of the square that contains the circle, and its width and height. Here is a picture to help:

QUESTION 5:

Fill in the blanks of the above method.