Color Test 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:

Some outside agent might change the Color object that color refers to, and the Circle object would now have a different color. This might not be wanted.

Color Test Applet

Here is an applet that tests the new features. It draws ten circles in red and ten circles in blue. The red circles are moved slightly to the left, and the blue circles are moved slightly to the right.

// assume that the drawing area is 200 by 200
public class TestCircleRedBlue extends JApplet
{
  Circle circ = new Circle();
  
  public void paint ( Graphics gr )
  { 
    setBackground(Color.black);

    int count = 1;
    while ( count <= 10 )
    {
      circ.setRadius(  (100/10)*count );

      circ.setColor( Color.blue );
      circ.setPosition( 100+count/2, 100 );
      circ.draw( gr );

      circ.setColor( Color.red );
      circ.setPosition( 100-count/2, 100 );
      circ.draw( gr );

      count = count + 1;
    }
  }
}

Here is what the applet draws.

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

QUESTION 14:

What would you do if you had a pair of red/blue 3D vision glasses?