Java
Home

Classe Token

 

/*
* Main.java
*
* Created on 5 de Fevereiro de 2007, 21:04
*/

package tokenizer;

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

import javax.swing.*;

/**
*
* @author adrw
*/

public class Main extends JFrame {

   private JLabel promptLabel;
   private JTextField inputField;
   private JTextArea outputArea;

   /** Creates a new instance of Main */
   public Main() {

      super("Testando a classe Tokenizer");

      Container container = getContentPane();
      container.setLayout( new FlowLayout() );

      promptLabel = new JLabel("Digite a string e precione enter");
      container.add( promptLabel );

      inputField = new JTextField(20);

      inputField.addActionListener(

      new ActionListener()
      {
         public void actionPerformed( ActionEvent event )
         {
            String stringToTokenize = event.getActionCommand();
   
            StringTokenizer tokens = new StringTokenizer( stringToTokenize );

            outputArea.setText("Numero de Elementos: " +
            tokens.countTokens() + "\n Os tokens são:\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();
   }

   /**
   * @param args the command line arguments
   */

   public static void main(String[] args) {

      Main application = new Main();

      //application.addWindowListerner

   }

}