//TokenDemo.java //Demonstrates the String Tokenizer and the textArea class //Takes a sentence, puts a word on each line import java.awt.*; import java.util.*; import java.applet.*; import java.awt.event.*; public class TokenDemo extends Applet implements ActionListener{ TextField txtInput = new TextField(); Button btnOk = new Button("OK"); TextArea txtOutput = new TextArea(); Panel pnlSouth = new Panel(); public void init(){ setLayout(new BorderLayout()); pnlSouth.setLayout(new GridLayout (0,1)); pnlSouth.add (new Label("Enter a sentence below and press the button")); pnlSouth.add(txtInput); Panel pnlButton = new Panel(); pnlButton.add(btnOk); pnlSouth.add(pnlButton); txtOutput.setEditable(false); add(txtOutput, BorderLayout.CENTER); add(pnlSouth, BorderLayout.SOUTH); btnOk.addActionListener(this); } // end init public void actionPerformed(ActionEvent e){ String inputString = txtInput.getText(); StringTokenizer reader = new StringTokenizer(inputString); String result = ""; while (reader.hasMoreTokens()){ result += reader.nextToken(); result += "\n"; } // end while txtOutput.setText(result); } // end actionPerformed } // end class def