import java.util.*;
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Example5_9 extends Applet implements ActionListener{
JTextArea textA; JTextField textF; JButton b1,b2;
public void init(){
setSize(250,150);
textA = new JTextArea("",5,10); textA.setBackground(Color.cyan);
textF = new JTextField("",10); textF.setBackground(Color.red); textF.setEditable(false);
b1 =new JButton("求和"); b2 =new JButton("重新开始");
add(textA);add(textF);add(b1);add(b2);
}
public void actionPerFormed(ActionEvent e){
if(e.getSource() == b1){
Sring s = textA.getText();StringTokenizer tokens = new StringTokenizer(s);
int n = tokens.countTokens(),sum = 0, i;//这行代码的意思
for(i=0;i<=n-1;i++){
String temp = tokens.nextToken();
sum += Integer.parseInt(temp);
}
textF.setText("" +sum);
}
else if (e.getSource() == b2){
textA.setText(null);
textF.setText(null);
}
}
}
没看到,呵呵。int n = tokens.countTokens(),sum = 0, i;//这行代码的意思?
追答b1.addActionListener(this)