栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验

[问答题] 下面是一个Applet程序,其功能是有2个按钮,分别为First和Second,以及一个Label构件。要求单击First时则能在Label中显示出Command: First,而单击Se

面试经验 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

[问答题] 下面是一个Applet程序,其功能是有2个按钮,分别为First和Second,以及一个Label构件。要求单击First时则能在Label中显示出Command: First,而单击Se

[问答题] 下面是一个Applet程序,其功能是有2个按钮,分别为First和Second,以及一个Label构件。要求单击First时则能在Label中显示出Command: First,而单击Second时则能显示出Command: Second,要求只能使用重载一次actionPerformed()方法。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。 注意:不改动程序的结构,不得增行或删行。 程序运行结果如下:
[问答题] 下面是一个Applet程序,其功能是有2个按钮,分别为First和Second,以及一个Label构件。要求单击First时则能在Label中显示出Command: First,而单击Se
import java.awt.*; import java.awt.event.*; import java.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(A


参考答案:


问题解析:

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的方法。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/250054.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号