// copied liberally with few changes from Lewis and Loftus p. 598 // demonstrates use of recursion graphically import java.awt.*; import javax.swing.JApplet; public class TiledPictures extends JApplet { private static final long serialVersionUID = 1L; private final int APPLET_WIDTH = 320; private final int APPLET_HEIGHT = 320; private final int MIN = 20; // smallest picture size private Image vangogh, sunflower, daffodil; /* * loads the images */ public void init( ) { vangogh = getImage(getDocumentBase( ), "vangogh.jpg"); sunflower = getImage(getDocumentBase( ), "sunflower.jpg"); daffodil = getImage(getDocumentBase( ), "daffodil.jpg"); setSize(APPLET_WIDTH, APPLET_HEIGHT); } /* * draws the three images, then calls itself recursively */ public void drawPictures(int size, Graphics page) { page.drawImage(sunflower, 0, size/2, size/2, size/2, this); page.drawImage(daffodil, size/2, 0, size/2, size/2, this); page.drawImage(vangogh, size/2, size/2, size/2, size/2, this); if (size > MIN) { drawPictures(size/2, page); } } /* * perform the initial call to the drawPictures method */ public void paint (Graphics page) { drawPictures(APPLET_WIDTH, page); } }