一个Java初学者的困惑:ActionEvent事件
我是初学者,请各位前辈帮我看一下下面代码哪里错了,为什么在dos窗口有下面的错误提示。拜托了。import java.awt.*;
import java.awt.event.*;
class D extends Frame implements ActionListener{
TextField text1,text2;
D(){
setLayout(new FlowLayout());
text1=new TextField(8);
text2=new TextField(8);
add(text1);
add(text2);
text1.addActionListener(this);
setBouns(100,100,150,150);
setVisible(true);
Validate();
}
public void actionperformed(ActionEvent e){
if(e.getSource()==text1){
String word=text1.getText();
if(word.equals("boy")){
text2.setText("男孩");
}
else{
text2.setText("没有该单词");
}
}
}
}
public class T{
public static void main(String args[]){
D win=new D();
}
}
在Dos窗口的显示是:
C:\>Documents and Setting\Administrator>E:
E:\>javac T.java
T.java:3:D不是抽象的,并且未覆盖java.awt.event.ActionListener中的抽象方法actionperformed(java.awt.event.ActionEvent)
class D extends Frame implements ActionListener
^
T.java:12:找不到符号
符号:方法setBounds(int,int,int,int)
位置:类D
setBounds(100,100,150,150);
^
T.java:14:找不到符号
符号:方法Validate()
位置:类D
Validate();
^
3错误
E:\>
--------------------编程问答-------------------- 都是拼写错误,要注意:
import java.awt.*;
import java.awt.event.*;
class D extends Frame implements ActionListener
{
TextField text1,text2;
D()
{
setLayout(new FlowLayout());
text1=new TextField(8);
text2=new TextField(8);
add(text1);
add(text2);
text1.addActionListener(this);
setBounds(100,100,150,150); //setBounds(); not setBouns.
setVisible(true);
validate(); //validate();not Validate().
}
public void actionPerformed(ActionEvent e) //actionPerformed(). not actionperformed.
{
if(e.getSource()==text1)
{
String word=text1.getText();
if(word.equals("boy"))
{
text2.setText("男孩");
}
else
{
text2.setText("没有该单词");
}
}
}
}
public class T
{
public static void main(String args[])
{
D win=new D();
}
}
补充:Java , Java SE