Drawing 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.

What do you suppose happens if you forget the match to a <head> tag?

Answer:

The rest of the file is regarded as part of the head, and will not show up in the browser as you expect.

Drawing Circles

The previous applets in this chapter have only printed text. Here is an applet that draws a circle.

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

// assume that the drawing area is 150 by 150
public class JustOneCircle extends JApplet
{
  final int radius = 25;

  public void paint ( Graphics gr )
  { 
    setBackground( Color.lightGray );
    gr.drawOval( (150/2 - radius), (150/2 - radius), radius*2, radius*2 );
   }
}

Here is what the applet paints with your Web browser:

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


QUESTION 13:

What is the name of the method that drew the circle?