首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下面是一个Applet程序,其功能是有2个按钮,分别为First和Second,以及一个Label构件。要求单击First时则能在Label中显示出Command: First,而单击Second时则能显示出Command: Second,要求只能使用重载
下面是一个Applet程序,其功能是有2个按钮,分别为First和Second,以及一个Label构件。要求单击First时则能在Label中显示出Command: First,而单击Second时则能显示出Command: Second,要求只能使用重载
admin
2013-02-25
24
问题
下面是一个Applet程序,其功能是有2个按钮,分别为First和Second,以及一个Label构件。要求单击First时则能在Label中显示出Command: First,而单击Second时则能显示出Command: Second,要求只能使用重载一次actionPerformed()方法。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。
注意:不改动程序的结构,不得增行或删行。
程序运行结果如下:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code=ex3_3.class width=800 height=400>
</applet>
*/
public class ex3_3 extends Applet implements ActionListener
{
private String str="ok";
private Label 1;
private Button btn;
public void init( )
{
setLayout(null);
1=new Label(str);
1.reshape(10,10,150,30);
add(1);
btn=new Button("First");
btn.reshape(10,50,60,20);
1.addActionListener(this);
add(btn);
btn=new Button("Second");
btn.reshape(10,100,60,20);
btn.setActionCommand("First");
btn.addActionListener(this);
add(btn);
}
public void actionPerformed(ActionEvent ae)
{
str="Command:"+ae.getActionCommand( );
btn.setText(str);
}
}
ex3_3.html
<HTML>
<HEAD>
<TITLE>ex3_3</TITLE>
</HEAD>
<BODY>
<applet code="ex3_3.class"width=800 height=400>
</applet>
</BODY>
</HTML>
选项
答案
Btn.addActionListener(this) Btn.setActionCommand(“second”) 1.setText(str)
解析
本题主要考查Java语言中高级事件ActionEvent和AWT基本构件Label的常用方法的使用。解题关键是熟练掌握动作事件ActionEvent和Label构件的常用方法。在本题中,第1处,明确注册的事件监听器是监听按钮的,而不是Label的;第2处,调用ActionEvent的setActionCommand()方法改变了ActionCommand,使按下第二个按钮时显示Command: second而不是Command: First。第3处,调用Label的setText()方法,而不是Button的方法。
转载请注明原文地址:https://kaotiyun.com/show/rR2p777K
本试题收录于:
二级Java题库NCRE全国计算机二级分类
0
二级Java
NCRE全国计算机二级
相关试题推荐
以下程序的输出结果是()。s=2foriinrange(1,10):s+=iprint(s)
以下关于数据维度的描述,错误的是()。
设循环队列的存储空间为Q(1:50),初始状态为front=rear=50。经过一系列正常的入队与出队操作后,front-1=rear。为了在该队列中寻找值最大的元素,在最坏情况下需要比较的次数为()。
表达式eval(’500//10’)的结果是()。
下列数据流图构造规则中正确的是()。
关于数据库管理阶段的特点,下列说法中错误的是()。
下面选项中不是关系数据库基本特征的是()。
软件需求分析阶段的工作可以概括为4个方面:______、需求分析、编写需求规格说明书和需求评审。
通过实现Rmmable接口创建线程,请在下面横线处填写代码完成此程序。publicclassThreadTest{publicstaticvoidmain(Stringargs[]){
按照流的方向来分,I/O流包括输入流和【】。
随机试题
TheNationalTrusthasworkedforthepreservationofplacesofhistoricinterestandnaturalbeautyinEngland,WalesandNorth
肝脏的大小多以哪项来测定()
采用仲裁方式解决合同纠纷的原则是( )。
根据《大中型水电工程建设风险管理规范》GB/T50927—2013,对于损失小、概率大的风险,施工单位宜采取的风险处置方法是()。
某施工企业承担了一幢六层房屋的施工任务。根据项目管理目标责任书中规定的各项职责,该工程的施工方项且经理组织有关人员完成了项目组织结构模式的确定、施工组织设计的编制等准备工作。在第二层施工时,旁站监理员发现施工人未按施工组织设计中的要求进行操作,存在质量隐患
新星公司是一家小型公司。创业初期,降低成本、提高销售额成为公司的总目标。由于业务繁忙,公司没有时间制定一套正式的完整的绩效考评评价制度,只是由以前公司老总王某兼任人力资源总监,采取了一些补救措施。如:他会不定期地对工作业务好的员工提出表扬,并予以物质奖励;
曹操:张辽:《三国演义》
简述北大西洋公约组织的建立及其扩展。(首都师范大学2002年世界近现代史真题)
岗位培训
EffectiveLectureStrategiesLecturalgia:painfullecture;causeofmorbidityforbothteachersandlearnersLectures:promotes
最新回复
(
0
)