问答题

本程序是一个Applet,实现了简单的英汉和汉英单词的互查。在页面中有三个文本框,分别为中文单词文本框、英文单词文本框和结果文本框,在英文单词文本框中输入英文单词后回车,如果存在该单词,则在结果文本框中输出对应的中文含义,如果不存在则输出“没有该单词”。同样,在中文单词文本框中输入中文单词后回车,如果查找到对应的英文单词,就在结果文本框中输出,否则输出“没有该单词”,如图所示。


import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class exam_67 ______
{ TextField text1,text2,text3;
Label lab1,lab2,1ab3;
public void init ()
{ text1=new TextField(10);
text2=new TextField(10);
text3=new TextField(10);
lab1=new Label ("请输入英文单词: ");
lab2=new Label ("请输入中文单词:");
lab3=new Label("结果:");
add (lab1);add (text1);
add (lab2); add (text2);
add (lab3);add (text3);
text1, addActionListener (this);
text2, addActionListener (this);
}
public void actionPerformed (ActionEvent e)
{ if(______)
{ String word=text1.getText();
if (word.equals ("boy"))
{ text3.setText ("男孩");
}
else if (word.equals ("girl"))
{ text3.setText ("女孩");
}
else if (word.equals ("sun"))
{ text3.setText ("太阳");
}
else
{ text3, setText ("没有该单词");
}
}
else if(e.getSource()==text2)
{ String word=text2.getText();
if (word.equals ("男孩"))
{ text3, setText ( "boy" );
}
else if (word.equals("女孩"))
{ text3.setText("girl");
}
else if (word.equals("太阳"))
{ text3.setText ("sun");
}
else
{ text3.setText ("没有该单词");
}
}
}
}


exam_67.html:
<html>
<head><title>exam_67</title></head>
<body>
<applet code="exam_67.class" width="250" height="500">
</applet>
</body>
</html>

【参考答案】

第1处:extends Applet implements ActionListener
第2处:e.getS......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
热门 试题