From http://cs.smu.ca/~porter/csc/465/code/horstmann/ch06/scene3/