主题:求助
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Example4_2 extends Applet implements ActionListener
{
TextArea txt1=new TextArea(7,35);
TextArea txt2=new TextField(35);
String str="TextArea 可以编辑多行文本。\n"+
"TextArea 编辑和显示多行文本,\n"+
"TextArea 是显示多行文本的编辑器。";
public void init()
{
txt1.setText(str);
add(txt1);
add(txt2);
txt2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String s;
if(e.getSource()==txt2)
{
s=txt2.getText();
txt1.append("\n"+s);
}
}
}
错误:
F:\111\Example4_2.java:7: incompatible types
found : java.awt.TextField
required: java.awt.TextArea
TextArea txt2=new TextField(35);
^
F:\111\Example4_2.java:17: cannot resolve symbol
symbol : method addActionListener (Example4_2)
location: class java.awt.TextArea
txt2.addActionListener(this);
^
2 errors
Process completed.
java.lang.NoClassDefFoundError: Example4_2
Exception in thread "main"
Process completed.
import java.awt.*;
import java.awt.event.*;
public class Example4_2 extends Applet implements ActionListener
{
TextArea txt1=new TextArea(7,35);
TextArea txt2=new TextField(35);
String str="TextArea 可以编辑多行文本。\n"+
"TextArea 编辑和显示多行文本,\n"+
"TextArea 是显示多行文本的编辑器。";
public void init()
{
txt1.setText(str);
add(txt1);
add(txt2);
txt2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String s;
if(e.getSource()==txt2)
{
s=txt2.getText();
txt1.append("\n"+s);
}
}
}
错误:
F:\111\Example4_2.java:7: incompatible types
found : java.awt.TextField
required: java.awt.TextArea
TextArea txt2=new TextField(35);
^
F:\111\Example4_2.java:17: cannot resolve symbol
symbol : method addActionListener (Example4_2)
location: class java.awt.TextArea
txt2.addActionListener(this);
^
2 errors
Process completed.
java.lang.NoClassDefFoundError: Example4_2
Exception in thread "main"
Process completed.