See also http://ejohn.org/apps/learn/ and http://code.pageforest.com/ and http://www.stanford.edu/class/cs101/
And similar ideas for teaching java interactively in the browser: http://ijava.cs.umass.edu/ http://math.hws.edu/javanotes/
The idea itself is old, search for 'active essays' for example, and most recently wolfram alpha's computational document format.