TAILIEUCHUNG - Java Programming for absolute beginner- P14

Java Programming for absolute beginner- P14:Hello and welcome to Java Programming for the Absolute Beginner. You probably already have a good understanding of how to use your computer. These days it’s hard to find someone who doesn’t, given the importance of computers in today’s world. Learning to control your computer intimately is what will separate you from the pack! By reading this book, you learn how to accomplish just that through the magic of programming. | 2 25 03 8 52 AM Page 218 k 0 c c 0 2 V 0 a c E E s k a o k a s s Telling the Story Creating the MadLib Game Frame The program uses a MadDialog object to retrieve user input. The MadLib class extends Frame. It listens for when the user closes the MadDialog dialog box and then builds the story and displays it in its un-editable TextArea. The MadDialog Frame itself will remain hidden until after the story is already built. Here s why. The MadDialog object is modal and it is shown first by calling true . It will maintain focus until it is hidden again. When the user clicks the x on the MadDialog window the buildStory method is called before the dialog is actually closed. Once the story is done the MadDialog will disappear and the MadLib will display the completed story. The buildStory method itself works by creating an array of Strings that represent segments of the story that break where words should be inserted. The String getStringArray method defined in the MadDialog class returns the String array sorted in the order they should be inserted into the story. This makes the two arrays indices correspond with each other so they are processed in a for loop to build the story. Here is the source for . MadLib A MadLib game import . import . public class MadLib extends Frame implements WindowListener private TextArea display private MadDialog dialog public MadLib super MadLib Game display new TextArea 7 60 new Font Timesroman 16 false add display addWindowListener this setLocation 100 150 pack dialog new MadDialog this this 150 100 true setVisible true team Line - live informative Non-cost and Genuine Please purchase PDF Split-Merge on to remove this watermark. 2 25 03 8 52 AM Page 219 219 public static void .