首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下面是一个Applet程序,其功能是实现对JButton类的扩展,封装成上网助力一样的按钮类,每个按钮对象对应一个 URL地址,点击则访问相应的URL。要求在窗口中从上到下排列3个这样的按钮。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。
下面是一个Applet程序,其功能是实现对JButton类的扩展,封装成上网助力一样的按钮类,每个按钮对象对应一个 URL地址,点击则访问相应的URL。要求在窗口中从上到下排列3个这样的按钮。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。
admin
2009-01-15
22
问题
下面是一个Applet程序,其功能是实现对JButton类的扩展,封装成上网助力一样的按钮类,每个按钮对象对应一个 URL地址,点击则访问相应的URL。要求在窗口中从上到下排列3个这样的按钮。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。
注意:不改动程序的结构,不得增行或删行。
程序运行结果如下:
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ex28_3 extends JApplet implements ActionListener {
ButtonURL[] btnURL = new ButtonURL[3];
public void init() {
btnURL[0] = new ButtonURL("新浪网","http://www.sina.com.cn/");
btnURL[1] = new ButtonURL("163","http://www.163.com/");
btnURL[2] = new ButtonURL("搜狐","http://www.sohu.com/");
GridLayout gl = new GridLayout(1,3);
getContentPane().setLayout(gl);
for (int i = 0; i < btnURL.length; i++) {
btnURL
.addActionListener(this);
getContentPane().add(btnURL
);
}
}
public void actionPerformed(ActionEvent ae) {
ButtonURL btnClick =ae.getSource();//获取发生事件的对象
try {
URL load = new URL(btnClick.strAddr);
getAppletContext().showDocument(strAddr);
} catch (MalformedURLException e) {
showStatus("Bad URL:" + btnClick.strAddr);
}
}
}
class ButtonURL extends JButton {
String strAddr;
ButtonURL(String strLabel, String strAddress) {
super(strLabel);
strAddr = strAddress;
}
}
ex28_3, html
<HTML>
<HEAD>
<TITLE>ex28_3</TITLE>
</HEAD>
<BODY>
<applet code="ex28_3.class" width=800 height=400 >
</applet>
</BODY>
</HTML>
选项
答案
new GridLayout(3,1) (ButtonURL)ae.getSource() showDocument(load)
解析
本题主要考查面向对象的基本程序设计思想和Applet事件处理机制及Applet和Application相结合的程序设计。解题关键是熟悉swing的基本构件,并会根据需要进行扩展,这里的ButtonURL类就是对JButton类的扩展,熟悉布局的基本操作等。本题中,第1处,按题目要求,应该是纵向排列的3个按钮;第2处,ae对象调用getSource()方返回的是JButton类的对象,这里需要ButtonURL的对象,所以需要进行转换;第3处,参数错误,应该是对象btnClick的成员变量strAddr的值。
转载请注明原文地址:https://kaotiyun.com/show/fHnp777K
本试题收录于:
二级Java题库NCRE全国计算机二级分类
0
二级Java
NCRE全国计算机二级
相关试题推荐
在考生文件夹下创建一个名为mymenu.mnx的下拉式菜单,并生成菜单程序mymenu.mpr。运行该菜单程序时会在当前VisualFoxPm系统菜单的“帮助”菜单之前插入一个“考试”菜单,如下图所示。“统计”和“返回”菜单命令的功能都通过执
在考生文件夹下有student(学生)、course(课程)和score(选课成绩)3个表,利用SQL语句完成如下操作:1.查询每门课程的最高分,要求得到的信息包括“课程名称”和“分数”,将查询结果存储到max表中(字段名是“课程名称”和“分数”
在考生文件夹下完成下列操作:(1)编写程序文件two.prg并执行。计算“01”组(歌手编号的前2位)歌手的得分,并将结果存入自由表FINAL中。FINAL包含“歌手姓名”和“得分”两个字段,“得分”取各评委所打分数的平均值。FINAL中的结果按
在考生文件夹下完成如下简单应用:1.通过一对多表单向导新建一个名为sport_form的表单。要求:把“国家”作为父表并选择“国家名称”字段作为显示字段,“获奖牌情况”为子表并选择“项目名称”和“名次”字段作为显示字段,通过“国家代码”
在考生文件夹下完成如下简单应用:1.用SQL语句完成下列操作:列出所有与“红”颜色零件相关的信息(供应商号、工程号和数量),并将查询结果按数量降序存放于表supply_temp中。2.新建一个名为menu_quick的快捷菜单,菜单中有两个菜单
在考生文件夹下,打开名称为CDB的商品销售数据库,完成如下综合应用:创建一个标题名为“顾客购买商品查询”、文件名为GK的表单,如下图所示。表单要求如下:(1)在该表单中设计两个标签、两个文本框、一个表格控件和两个命令按钮。
打开考生文件夹下的sport_proieet项目,项目中有一个名为sport_form的表单文件,表单中包括3个命令按钮。请完成如下操作:(1)编写并运行程序Four.prg。程序功能是:根据“国家”和“获奖牌情况”两个表统计并生成一个
在考生文件夹下已有一个菜单文件mymenu.mnx,运行相应的菜单程序时会在当前VFP系统菜单的末尾追加一个“考试”子菜单,如图3-9所示(在菜单设计器环境下,使用“常规选项”命令打开相应对话框,在“位置”中指定“追加”)。在考生文件夹下还有一个表单文
线程模型在Java中是由【】类进行定义和描述的。
Java中的字符输出流都是抽象类_____________的子类。
随机试题
男性,35岁,因蛋白尿待查入院,24小时尿蛋白定量3.8g,血白蛋白30g/L,肾活检示:轻度系膜增生性肾炎。该患者最不易出现的并发症
在相同增压比条件下,压气机可逆绝热压缩时消耗功为Ws,则实际绝热压缩消耗的功W*为()。
人行地道作为城市公用设施,在使用和美观上较好,但是工程和维修费用较高。一般在(),可考虑修建人行地道。
基金财务报表附注应披露()。
个人住房贷款的对象应满足的条件包括()
社区工作的社会策划模式注重自上而下的改变,其特征包括()。
我国社会主义民主政治建设的艰巨性和长期性是由()决定的。
设函数f(u)具有二阶连续导数,z==16z(x2+y3).求f(u)的表达式.
Whatdoesthemanmean?
HowPsychologyCanHelpthePlanetStayCool[A]"I’mnotconvincedit’sasbadastheexpertsmakeout...It’severyoneelse
最新回复
(
0
)