import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TokenTest extends JFrame
 {
  private JLabel promptLabel;
  private JTextField inputField;
  private JTextArea outputArea;
  
  public TokenTest()
  
  {
   super("Testing Class StringTokenizer");
   
   Container container = getContentPane();
   container.setLayout(new FlowLayout());
   
   promptLabel = 
    new JLabel("Enter a sentence and press Enter");
   container.add(promptLabel);
   
   inputField = new JTextField(20);
   
   inputField.addActionListener
   
   (
    new ActionListener()
     {
     
       public void actionPerformed(ActionEvent event)
        {
         String stringTokenize = 
           event.getActionCommand();
         StringTokenizer tokens =
           new StringTokenizer(stringToTokenize);
         
         ouputArea.setText("Number of elements: " +
           tokens.countTokens() + "\nThe tokens are:\n");
           
         while(tokens.hasMoreTokens())
            outputArea.append(tokens.nextToken() + "\n");
         }
       }
    );
    
    container.add(inputField);
    
    outputArea = new JTextArea(10,20);
    outputArea.setEditable(false);
    container.add(new JScrollPane(outputArea));
    
    setSize(275,260);
    show();
    
   }
   
   
    public static void main(String ars[])
     {
      TokenTest application = new TokenTest();
      application.addWindowListener
      ( new WindowAdapter()
       {
        
         public void windowClosing(WindowEvent windowEvent)
          {
           Sy