HTML Page

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:

You put the circle anyplace you want and make it any radius. The following seems like a reasonable choice to me:

public class TestCircle extends JApplet
{
  Circle circ = new Circle( 100, 100, 25 );

  public void paint ( Graphics gr )
  { 
    circ.draw( gr );    
  }
}

HTML Page

To run the test applet a Web page is needed, perhaps called TestCircle.html:

<html>
<body>
<applet code="TestCircle.class"  width="200" height="200">
</applet>
</body>
</html>

The source file is compiled in the usual way and run with the appletviewer:

C:/>javac TestCircle.java
C:/>appletviewer TestCircle

(Or you can look at TestCircle.html with a Web browser.) Here is what the test applet draws:


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

The paint() method of the applet is called whenever the Web browser needs to paint the section of the screen reserved for the applet. To see that happen, reduce the size of your browser's window, then drag it around. On some computer systems you will see the applet's drawing area flicker as paint() repeatedly is called to redraw the area.

QUESTION 7:

How would you make the test applet draw more circles?