[计算机类试卷]国家二级(JAVA)机试模拟试卷87及答案与解析.doc

上传人:孙刚 文档编号:503624 上传时间:2018-11-29 格式:DOC 页数:5 大小:69KB
下载 相关 举报
[计算机类试卷]国家二级(JAVA)机试模拟试卷87及答案与解析.doc_第1页
第1页 / 共5页
[计算机类试卷]国家二级(JAVA)机试模拟试卷87及答案与解析.doc_第2页
第2页 / 共5页
[计算机类试卷]国家二级(JAVA)机试模拟试卷87及答案与解析.doc_第3页
第3页 / 共5页
[计算机类试卷]国家二级(JAVA)机试模拟试卷87及答案与解析.doc_第4页
第4页 / 共5页
[计算机类试卷]国家二级(JAVA)机试模拟试卷87及答案与解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级( JAVA)机试模拟试卷 87及答案与解析 一、基本操作题( 30分) 1 下面程序创建一个长宽均为 100的 Frame窗口,并且窗口的背景颜色是蓝色。请将程序补充完整。 注意:不改动程序结构,不得增行或删行。 import java.awt .*; public class ex1 extends Frame public static void main(String args) ex1 t=new ex1(); t.setSize(100,100); _ t.setVisible(true); 二、简单应用题( 40分) 2 在程序中,使用适当的布局管理器,在 Frame框的

2、 North位置添加一句提示信息,在 South位置添加一个单行文本框,在这个文本框中输入的内容将会显示在Center位置。运行结果如下图所示。 注意:请勿修改 main()主方法和其他已有语句内容,仅在横线处填入适当语句。 import java.awt.*; import java.awt.event.*; public class simple extends Frame public static void main(String args) simple frame=new simple(“simple“); frame.init(); frame.setSize(300,300);

3、 frame.show(); public simple(String name) super(name); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) _; ); public void init() setLayout(new_); Label labelTitle=new Label(“在本文框中输入字符串 , 可以早 Frame中间显示 “); Label showTextLabel=new Label(); TextField textField=new TextFiel

4、d(“请在这里输入字符串 “); textField.addActionListener(new AddStringListener(showTextLabel, textField); add(“North“, labelTitle); add(“Center“, showTextLabel); add(“South“, textField); class AddStringListener implements ActionListener Label label; TextField textField; public AddStringListener(Label label, Tex

5、tField textField) this.label=label; this.textField=textField; public void actionperformed(ActionEvent e) label.setText(textField.getText(); 三、综合应用题( 30分) 3 本程序的功能是监听对于菜单项和工具条按钮的操作。主窗口中有菜单、工具条和一个文字标签,菜单中有 “文件 ”项, “文件 ”菜单中包括菜单项 “新建 ”、 “保存 ”、“打印 ”、 “页面设置 ”和 “退出 ”,工具条上包括按钮 “新建 ”、 “保存 ”、 “打印 ”、 “页面设置 ”和

6、“退出 ”。单击任何一个菜单项或任何一个工具条按钮,文字标签都会显示哪个构件被选中。请更正题中带下划线的部分。运行结果如下图所示。 注意:不改变程序的结构,不得增行或删行。 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class advance extends JFrame private JLabel actionlnfo; public advance(String titleText) setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); sup

7、er(titleText); actionInfo=new JLabel(“事件信息 “); JToolBar tb=new JTooBar(); Menu file=new Menu( “文件 “ ); JMenuBar mb=new JMenuBar(); mb.add(file); NewAction na=new NewAction(actionInfo); file.add(na); tb.add(na); SaveAction sa=new SaveAction(actionInfo); file.add(sa); tb.add(sa); PrintAction pta=new P

8、rintAction(actionInfo); file.add(pra); tb.add(pra); PageSetAction psa=new PageSetAction(actionInfo); file.add(psa); tb.add(psa); ExitAction ea=new ExitAction(actionInfo); file.add(ea); tb.add(ea); setJMenuBar(mb); Container cp=getContentPane(); cp.setLayout(new BorderLayout(); cp.add(tb); cp.add(act

9、ionInfo, BorderLayout.CENTER ); setSize(350, 200); setVisible(true); public static void main(String args) new advance(“advance“); class NewAction extends AbstractAction JLabel label; public NewAction(JLabel label) super(“新建 “); this.label=label; public void actionPerformed(ActionEvent e) label.setTe

10、xt(“您选择了新建 “); class SaveAction extends AbstractAction JLabel label; public SaveAction(JLabel label) super(“保存 “); this.label=label; public void actionPerformed(ActionEvent e) label.setText (“您选择了保存 “); class printAction extends AbstractAction JLabel label; public PrintAction(JLabel label) super(“打印

11、 “); this.label=label; public void actionPerformed(ActionEvent e) label.setText (“您选择了打印 “); class PageSetAction extends AbstractAction JLabel label; public pageSetAction(JLabel label) super(“页面设置 “); this.label=label; public void actionPerformed(ActionEvent e) label.setText(“您选择了页面设置 “); class Exit

12、Action extends AbstractAction JLabel label; public ExitAction(JLabel label) super(“退出 “); this.label=label; public void actionPerformed(ActionEvent e) label.setText (“您选择了退出 “); 国家二级( JAVA)机试模拟试卷 87答案与解析 一、基本操作题( 30分) 1 【正确答案】 t.setBackground(Color.blue); 【试题解析】 本题是基本操作题,主要考查对图形用户界面的掌握。类 ex1继承了 Fram

13、e类,因此该类的实例 t就可以调用 Frame类的基本方法t.setBackground(Color.blue),由于题干要求窗口的背景颜色为蓝色,因此需要调用 Color.blue作为方法 setBackground 的参数。 二、简单应用题( 40分) 2 【正确答案】 System.exit(0) BorderLayout() 【试题解析】 本题考查知识点: AWT 库的使用,布局管理器的使用。解题思路:程序使用 label Title来显示提示信息,使用 text Field 来获取用户的输入,最后将用户输入的结果通过 showTextLabel 显示出来。 Frame的关闭按钮的处理

14、方式与 JFrame的方式不同, Frame必须手动实现退出按钮的事件处理机制,否则单击 关闭按钮程序不会做出响应。本题的第 1空就是对退出按钮事件响应的内容。BorderLayout布局管理器将容器分为五个区域: North、 South、 East、 West和 Center。可以指定构件放在哪个区域,但是每个区域只能放置一个构件。第 2个空即是为 Frame设置 BorderLayout类型的布局管理器。 三、综合应用题( 30分) 3 【正确答案】 setTitle(titleText) JMenu file=new JMenu(“文件 “) cp.add(tb,BorderLayou

15、t.NORTH)或 cp.add(“North“, tb) 【试题解析】 本题考查知识点:类的继承、 AWT和 Swing的区别、布局管理器的使用。解题思路:程序中声明了一个菜单构件、一个工具栏构件,声明了 5个事件添加到菜单和工具栏中。子类继承父类以后,可以调用父类的 public、protected 成员变量和成员方法。子类还可以使用变量 super,访问已经被隐藏或被覆盖了的父类成员变量和方法。题中, JFrame带一个参数的构造方法已经被子类 advance的构造方法覆盖。原题打算使用 super调用父类的构造方法,为 框架添加变量 titleText定义的名字。这样的操作可以实现,但

16、是 super变量要求必须写在其所在的方法的第一行,而本题中 super变量前还有语句setDefaultCloseOperation。因此在第 1条下划线的位置不能使用 super,只能调用set Title()方法,该方法可以为框架设置名字。 file是一个 AWT 构件 Menu 的对象,而它所在的容器 mb 是一个 Swing的 JMenuBar对象,两类不同的构件,实现的方法不一样,不能使用 add 方法进行添加。因此在第 2条下划线处需要把 file的类型改为 JMenu。容器定义了 BorderLayout 布局管理器以后,如果添加构件时不指明添加的位置,则会把该构件添加到 Center的位置。由于本题中不需要把名为 actionInfo的 JLabel 构件添加到 Center的位置,所以在第 3条下划线处,添加tb 构件时必须指明位置参数。本题答案中根据习惯把工具栏添加到容器的顶部,当然,添加到容器的 South、 East或 West位置也都正确。

展开阅读全文
相关资源
猜你喜欢
  • BS ISO IEC 25063-2014 9673 Systems and software engineering Systems and software product Quality Requirements and Evaluation (SQuaRE) Common Industry Format (CIF) for usability C.pdf BS ISO IEC 25063-2014 9673 Systems and software engineering Systems and software product Quality Requirements and Evaluation (SQuaRE) Common Industry Format (CIF) for usability C.pdf
  • BS ISO IEC 25066-2016 Systems and software engineering Systems and software Quality Requirements and Evaluation (SQuaRE) Common Industry Format (CIF) for Usability Evaluat.pdf BS ISO IEC 25066-2016 Systems and software engineering Systems and software Quality Requirements and Evaluation (SQuaRE) Common Industry Format (CIF) for Usability Evaluat.pdf
  • BS ISO IEC 25185-1-2016 Identification cards Integrated circuit card authentication protocols Protocol for Lightweight Authentication of Identity《识别卡 集成电路卡认证协议 轻量级身份认证协议》.pdf BS ISO IEC 25185-1-2016 Identification cards Integrated circuit card authentication protocols Protocol for Lightweight Authentication of Identity《识别卡 集成电路卡认证协议 轻量级身份认证协议》.pdf
  • BS ISO IEC 26300-1-2015 Information technology Open Document Format for Office Applications (OpenDocument) v1 2 OpenDocument Schema《信息技术 办公应用程序开放文档格式 (OpenDocument) v1 2 O.pdf BS ISO IEC 26300-1-2015 Information technology Open Document Format for Office Applications (OpenDocument) v1 2 OpenDocument Schema《信息技术 办公应用程序开放文档格式 (OpenDocument) v1 2 O.pdf
  • BS ISO IEC 26300-2-2015 Information technology Open Document Format for Office Applications (OpenDocument) v1 2 Recalculated Formula (OpenFormula) Format《信息技术 办公应用程序开放文档格式.pdf BS ISO IEC 26300-2-2015 Information technology Open Document Format for Office Applications (OpenDocument) v1 2 Recalculated Formula (OpenFormula) Format《信息技术 办公应用程序开放文档格式.pdf
  • BS ISO IEC 26300-3-2015 Information technology Open Document Format for Office Applications (OpenDocument) v1 2 Packages《信息技术 办公应用程序开放文档格式 (OpenDocument) v1 2 包》.pdf BS ISO IEC 26300-3-2015 Information technology Open Document Format for Office Applications (OpenDocument) v1 2 Packages《信息技术 办公应用程序开放文档格式 (OpenDocument) v1 2 包》.pdf
  • BS ISO IEC 26511-2012 Systems and software engineering Requirements for managers of user documentation《系统和软件工程 用户文档管理要求》.pdf BS ISO IEC 26511-2012 Systems and software engineering Requirements for managers of user documentation《系统和软件工程 用户文档管理要求》.pdf
  • BS ISO IEC 26512-2011 Systems and software engineering Requirements for acquirers and suppliers of user documentation《系统和软件工程 用户文件编制的需方和供方的要求》.pdf BS ISO IEC 26512-2011 Systems and software engineering Requirements for acquirers and suppliers of user documentation《系统和软件工程 用户文件编制的需方和供方的要求》.pdf
  • BS ISO IEC 26514-2008 Software and systems engineering - Requirements for designers and developers of user documentation《系统和软件工程 用户文件的设计者和开发者用要求》.pdf BS ISO IEC 26514-2008 Software and systems engineering - Requirements for designers and developers of user documentation《系统和软件工程 用户文件的设计者和开发者用要求》.pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1