问答题
本程序是一个Applet,功能是监听对于文本域中文本的选择。页面中有一个文本域、一个“复制”按钮和一个文本框,选中文本域中部分文字后,单击“复制”按钮,所选文字将显示在文本框中,如图所示。
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class exam_13 extends Applet implements ActionListener
{
TextArea ta=new TextArea(5,30);
TextField tf=new TextField(30);
Button button=new Button("复制");
String text="AWT提供基本的GUI组件, \n"+"具有可以扩展的超类, \n"+"它们的属性是继承
的。\n";
public void init()
{
setLayout(new
FlowLayout(FlowLayout.left));
ta.setText(text);
ta.setEditable(true);
add (ta);
add (button);
add (tf);
ta. addActionListener (this);
}
public void actionPerformed(ActionEvent e)
{
String s;
s=ta.qetSelectText();
if (e.getSource () ==button)
tf.setText(s);
}
}
exam_13.html:
<html>
<head><title>exam_13</title></head>
<body>
<applet code=exam_13.class width=500 height=500></applet>
</body>
</html>
【参考答案】
第1处:setLayout(new FlowLayout(FlowLayout.LEFT))
第2处:butt......
(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)