Problem
Using String Methods to Count Words
Word processing programs also can count and then display the number of words in a document, in addition to the number of characters. Using methods from the String class, write a program that will count the number of words which are separated by blanks in a String. For simplicity, use strings without punctuation or other white space characters (tabs, newlines, etc.). Use a JTextArea to allow a user to enter the text and allow the text area to scroll, if necessary. When the user clicks a button to count the words, the total number of words counted is displayed in a text box that cannot be modified by the user. For Java 5.0, use static imports where appropriate. For an additional challenge, allow words to be separated by multiple blanks and by one or more newline characters. Figure 9-50 displays sample output.
![626_Figure 9-50.jpg](https://secure.tutorsglobe.com/CMSImages/626_Figure 9-50.jpg)