The Crayons Applet (LLC 4.10)

(Dec. 2011, revised Dec. 2021) 🅭🅯🄎 4.0 Daniel Woodworth

This is exercise 4.10 from Java Solutions for AP Computer Science (John Lewis, William Loftus, Cara Cocking), which originally involved implementing a Crayon class and instantiating it in different colors to draw a whole crayon box. Some students took this farther and made applets that draw very artistic and aesthetically pleasing crayon boxes.

Clearly, this is not the direction I went with—my crayon box is very plain and sort of ugly. Instead, I decided to make the crayons functional, so along with drawing crayons the applet also lets the user draw with crayons. To do this, just choose a crayon from the box by clicking on it and the applet will pull it out and switch to a different screen with a drawing canvas. Just like real crayons, these virtual crayons also get duller as they're used, but they can be re-sharpened to a fine point by using the crayon sharpener in the top-left corner. When done with drawing, click outside of the applet area to put the crayon back in the box.

Though Java applets are dead and no modern browser will run the original applet from ten years ago, I've translated the code to JavaScript so you can still experience it above.

External Sources