578 Strings and Characters (Multiple domain web hosting) Chapter 10 70 application.addWindowListener(

578 Strings and Characters Chapter 10 70 application.addWindowListener( 71 72 // anonymous inner class 73 new WindowAdapter() { 74 75 // handle event when user closes window 76 public void windowClosing( WindowEvent windowEvent ) 77 { 78 System.exit( 0 ); 79 } 80 81 } // end anonymous inner class 82 83 ); // end call to addWindowListener 84 85 } // end method main 86 87 } // end class TokenTest Fig. 10.20 Tokenizing strings with a StringTokenizerobject (part 3 of 3). The statement at lines 44 45 uses the StringTokenizermethod countTokens to determine the number of tokens in the Stringto be tokenized. The condition in the while structure at lines 47 48 StringTokenizer method hasMoreTokens to determine whether there are more tokens in the String being tokenized. If so, the append method is invoked for the JTextArea outputArea to append the next token to the Stringin the JTextArea. The next token is obtained with a call to StringTokenizermethod nextTokenthat returns a String. The token is output followed by a newline character, so subsequent tokens appear on separate lines. If you would like to change the delimiter String while tokenizing a String, you may do so by specifying a new delimiter string in a nextTokencall as follows: tokens.nextToken( newDelimiterString ); This feature is not demonstrated in the program. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply