java 文本框的小问题
JButtonb4=newJButton();Stringtext1,text2;JTextAreat1=newJTextArea();JTextAreat2=newJT...
JButton b4=new JButton();
String text1,text2;
JTextArea t1=new JTextArea();
JTextArea t2=new JTextArea();
text1=t1.getText();
text2=t2.getText();
b4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
t1.append(text2);
t2.repaint();
}
}
);
我想在单击b4后,把文本区t2 的文本添加到文本区t1里,t2清空,应怎么改?
t1,t2,text2下面画红色波浪线,应该有错吧!我怎么看不出有什么错误?
编译提示:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Cannot refer to a non-final variable t1 inside an inner class defined in a different method
Cannot refer to a non-final variable text2 inside an inner class defined in a different method
Cannot refer to a non-final variable t2 inside an inner class defined in a different method
at QQ.main(QQ.java:106) 展开
String text1,text2;
JTextArea t1=new JTextArea();
JTextArea t2=new JTextArea();
text1=t1.getText();
text2=t2.getText();
b4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
t1.append(text2);
t2.repaint();
}
}
);
我想在单击b4后,把文本区t2 的文本添加到文本区t1里,t2清空,应怎么改?
t1,t2,text2下面画红色波浪线,应该有错吧!我怎么看不出有什么错误?
编译提示:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Cannot refer to a non-final variable t1 inside an inner class defined in a different method
Cannot refer to a non-final variable text2 inside an inner class defined in a different method
Cannot refer to a non-final variable t2 inside an inner class defined in a different method
at QQ.main(QQ.java:106) 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询