首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请完成下列Java程序:创建一个具有2行3列的GridLayout管理器,包括Choice,Label,Button构件,布局为第1行包括一个Choice构件(包括2个选项item1和item2),一个Label构件(当选择Choice构件中的选项时,La
请完成下列Java程序:创建一个具有2行3列的GridLayout管理器,包括Choice,Label,Button构件,布局为第1行包括一个Choice构件(包括2个选项item1和item2),一个Label构件(当选择Choice构件中的选项时,La
admin
2009-12-22
20
问题
请完成下列Java程序:创建一个具有2行3列的GridLayout管理器,包括Choice,Label,Button构件,布局为第1行包括一个Choice构件(包括2个选项item1和item2),一个Label构件(当选择Choice构件中的选项时,Label构件显示相应的名称,即如果单击item1则Label中显示item1),和一个exit按钮(单击则退出应用程序),第2行包括3个Button构件。程序运行结果如下:
注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
import java.awt.*;
import java.awt.event.*;
public class ex2_2 extends Frame implements ActionListener,ItemListener
{
private Label 1;
private String str="Label";
private Choice choice2_2;
public static void main(String[] args)
{
new ex2_2();
}
ex2_2
{
setLayout(______);
choice2_2=new Choice();
choice2_2.addItem("item1");
choice2_2.addItem("item2");
choice2_2.______;
add(choice2_2);
1=new Label(str);
add(1);
Button exit2_2=new Button("exit");
Exit2_2.addActionListener(this);
add(exit2_2);
for(int i=0;i<3;i++)
add(new Button("button" +i));
setSize(300,300);
pack();
show();
}
public void actionPerformed(ActionEvent event)
{
If (event.getActionCommand().equals("exit"))
{
System.exit(0);
}
}
public void itemStateChanged(ItemEvent event)
{
Str=choice2_2.getSelectedItem();
1.setText(str);
}
}
选项
答案
new GridLayout(2,3) addltemlistener(this)
解析
本题主要考查Java常用构件Choice和高级事件ItemEvent以及GridLayout布局管理器的用法。解题关键是,熟悉GridLayout布局管理器和ItemEvent的用法。ItemEvent在教材中并没有给出确切的用法,但是可以根据ActionEvent的addActionEvent()方法和重载actionPerformed()方法来完成对动作事件监听的用法来类推ItemEvent事件的监听方法,这里要求有根据已有知识进行单一反三的能力。
转载请注明原文地址:https://kaotiyun.com/show/ucnp777K
本试题收录于:
二级Java题库NCRE全国计算机二级分类
0
二级Java
NCRE全国计算机二级
相关试题推荐
下列程序段执行以后,内存变量y的值是x=34567y==0DOWHILEx>0y=x%10+y*10x=int(x/10)ENDD
在VisualFoxPro中,下面描述正确的是
①建立一个文件名和表单名均为myform的表单,表单中包括一个列表框(IAstl)和两个命令按钮(Command1和Command2),Command1和Command2的标题分别为“计算”和“退出”。②列表框(List1)中应显示组号,通过RowSou
(1)编写程序three.prg完成下列操作:根据“外汇汇率”表中的数据产生rate表中的数据。要求:将所有“外汇汇率”表中的数据插入rate表中并且顺序不变,由于“外汇汇率"中的“币种1”和“币种2”存放的是外币名称,而rate表中的“币种1代码”和“
在VisualFoxPro中有如下内存变量的赋值语句:X={^2008-08-088:00:00AM}Y=.y.Z="12.34”执行上述语句之后,内存变量的X、Y、Z的数据类型为()
下列关于下拉菜单和快捷菜单的说法中,错误的是()。
源程序文档化要求程序应加注释。注释一般分为序言性注释和____________。
对长度为8的数组进行快速排序,最多需要的比较次数为()。
J2ME是为嵌入式和移动设计提供的Java平台,它的体系结构由______组成。()
Applet是能够嵌入到【】页面中,并能够在浏览器中运行的Java类。
随机试题
政策:促进:约束
A.人虱B.鼠蚤C.螨D.蜱E.蚊传播地方性斑疹伤寒的媒介昆虫是
青春期功能失调性子宫出血的内分泌特点是
在流行病学实验中为防止偏倚常采用盲法,如果研究者、研究对象、负责资料收集和分析的人员都不了解情况,则这种盲法称为
男性,43岁,因“持续高热、咽喉疼痛1周”就诊。查体:体温39.5℃,贫血貌,咽部充血,双侧扁桃腺Ⅲ度肿大,可见脓肿,全身浅表淋巴结及肝脾未触及,胸骨无压痛。化验:血常规Hb50g/L,RBC1.8×1012/L,WBC1.9×109/L.PLT1
企业投资项目可行性研究的主要内容中,经济影响分析不包括()。
《汽车贷款管理办法》与《汽车消费贷款管理办法(试点办法)》的不同点包括()。
银行在收取承担费时,不可以进行的行为是()。
下列各项中,不属于初步业务活动的是()。
[*]
最新回复
(
0
)