JTextArea监听器具体代码

来源:百度知道 编辑:UC知道 时间:2024/06/23 09:28:20
符号: 方法 addActionListener(<匿名 java.awt.event.ActionListener>)
位置: 类 javax.swing.JTextArea
t4.addActionListener(new ActionListener()
^
出现这样的问题 本人估计监听器的问题

t4= new JTextArea(); //对话窗口
t4.setEnabled(false);
t4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
sendData(t4.getText());
}
});

1.t4需要定义为final JTextArea t4=new JTextArea(),因为他下面要被做为局部变量传递给匿名内部类。
2.如果你是在main函数中运行该方法,sendData必须定义为static。