Testing Applet

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 complete method is in the revised class definition, below.

Testing Applet

The class is now well enough defined to do some testing. We need to write an applet for testing. Here is the current version of the Circle class, with a testing applet:

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

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
  void draw( Graphics gr )
  {
    int ulX = x-radius ; // X of upper left corner of rectangle
    int ulY = y-radius ; // Y of upper left corner of rectangle
    gr.drawOval( ulX, ulY, 2*radius, 2*radius );
  }

}

// assume that the drawing area is 200 by 200
public class TestCircle extends JApplet
{
  Circle circ = ;
  
  public void paint ( Graphics gr )
  { 
    circ.draw(  );    
  }
}

QUESTION 6:

Fill in the blanks with some reasonable values.