CHAPTER 74 — Recursion with Graphics

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.

created: 01/03/03; revised: 07/22/06

CHAPTER 74 — Recursion with Graphics

This chapter builds an applet that shows how complicated-appearing graphics may be created with recursive Java methods. The applet draws the snowflake figure from the first chapter on recursion.

Chapter Topics:

  • Review of applets
  • Review of applet graphics
  • The SnowFlake applet

Most of the programs used to illustrate recursion in the previous chapters could easily be written using iteration in place of recursion. Of course, it is always possible to use one instead of the other. Sometimes iteration is the obvious choice; sometimes recursion. This chapter discusses an applet that is much easier to write with recursion.

You may wish to review the first chapter on applets (chapter 36) if your recollection of applets is hazy.

QUESTION 1:

(Hazy Review: ) What is the method of an applet that is called by a Web browser when it needs to fill in the part of the screen that contains the applet?