This code was taken from the book Core Java, Volume II--Advanced Features by Cay S. Horstmann and Gary Cornell