// ScrollBarsDemo.java
// Example of using applying scroll bars to JTextArea
// Exactly the same as StringTokenizerDemo but with scroll bars added
// APPLET CODE="ScrollBarsDemo" HEIGHT=400 WIDTH=600
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class ScrollBarsDemo extends JApplet implements ActionListener {
	// GUI components
	Container c;
	JLabel prompt;
	JTextField input;
	JTextArea output;

	public void init( ) {
		c = getContentPane( );
		c.setLayout( new FlowLayout( ) );
		prompt = new JLabel( "Enter a sentence and hit Enter" );
		c.add( prompt );
		input = new JTextField( 50 );
		input.addActionListener( this );
		c.add( input );
		output = new JTextArea( 10, 40 );
		output.setEditable( false );
		c.add( new JScrollPane( output ) );	// adds the JScrollPane to JTextArea
	}

	public void actionPerformed( ActionEvent e ) {
		String givenString = input.getText( );
		StringTokenizer tokens = new StringTokenizer( givenString );

		output.setText( "" );  // clears the text area

		output.append( "Number of tokens:  " + tokens.countTokens( ) + "\nThe tokens are:\n" );
		
		while( tokens.hasMoreTokens( ) )
			output.append( tokens.nextToken( ) + "\n" );
	}
}