import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test extends JFrame{
private JLabel promptLabel;
private JTextField inputField;
private JTextArea outputArea;
public test(){
super("ceshi StringTokenizer");
Container container=getContentPane();
container.setLayout(new FlowLayout());
promptLabel=new JLabel("shu ru yi ge shu");
container.add(promptLabel);
inputField=new JTextField(20);
inputField.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
StringTokenizer tokens=new StringTokenizer(event.getActionCommand());
outputArea.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,240);
setVisible(true);
}
public static void main(String args[]){
test application=new test();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
评论