java吧 关注:1,291,736贴子:12,820,773
  • 1回复贴,共1

求救 急!!!!!

只看楼主收藏回复

import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
class Window extends JFrame implements ActionListener
{ JTextArea text1,text2;
Window(String s)
{ setLayout(new FlowLayout());
    text1=new JTextArea(10,20);
     text2=new JTextArea(10,20);
       add(text1);
         add(text2);
        text1.addActionListener(this);
          setVisible(true);
    validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }
public void actionPerformed(ActionEvent e)
{
StringTokenizer he=new StringTokenizer(text1.getText()," ");
int sum=0;int x;
while(he.hasMoreTokens())
{String str=he.nextToken();
x=Integer.parseInt(str);
sum=sum+x;
}
String str2=String.valueOf(sum);
text2.setText(str2);
}
}
public class Eva
{ public static void main(String args[])
{Window win=new Window("窗口");
   }
}
请问这个程序说找不到符号,就在text1.addActionListener(this);这里 


1楼2010-03-25 17:49回复
    • 123.8.231.*
    这句去掉就行了,原因很简单,因为JTextArea类中没有定义addActionListener成员方法,而text1是该类的对象。
    打个比方,就好像你想让一根木头会说话一样(呵呵)。


    2楼2010-03-25 19:03
    回复