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

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

1、国家二级( JAVA)机试模拟试卷 109及答案与解析 一、基本操作题( 30分) 1 下面的程序是用 do_while语句计算 10的阶乘。请在程序的每条横线处填写一个语句,使程序的功能完整。 注意:请勿改动 main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。 public class DoWhileLoop public static void main(_) int n=10; long result=1; do _ _ System. out.println( “10的阶乘为 : “+result); 二、简单应用题( 40分) 2 下列程序用来显示用户要求打开的图片。

2、在名为 “读取图像 ”的 JFrame框架中有一个单行文本框,用户可以在其中输入图片文件的文件名称,按下 “浏览图片 ”按钮以后,新生成一个对话框,将图片显示在这个对话框中, 运行结果如下图所示。请填写横线处的内容。 注意:请勿改动 main()主方法和其他已有语句内容,仅在横线处填入适当语句。 import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; public class Example2_9 public static void main(String args) JFrame

3、 frame = new FileNameFrame(“读取图像 “); frame.setDefaultCloseOperation(JFrame. EXIT ON CLOSE); frame.setSize(300, 100); frame.show(); class FileNameFrame extends JFram implements ActionListener JLabel inputLabel; JTextField fileNameText; JButton containtButton; public FileNameFrame(String titleText) su

4、per(titleText); inputLabel = new Jnabel(“请输入图像文件的名称 “); fileNameText = new JTextField(10); containtButton = new JButton(“浏览图片 “); fileNameText.addActionListener(this); containtButton.addActionListener(this); JPanel panel = new JPanel(); panel.add(fileNameText); panel.add(containtButton); Container c

5、ontaint = getContentPane(); containt.setLayout(new BorderLayout(3,3); containt.add(inputLabel, BorderLayout.NORTH); containt.add(panel, BorderLayout.CENTER); public void actionPerformed(ActionEvent e) String fileName = fileNameText.getText(); ImageIcon image = _; ImageDialog dlg = new ImageDialog(th

6、is); dlg.setImage(image); dlg.setTitle(fileName); dlg.show(); class ImageDialog extends JDialog JLabel imageLabel; public ImageDialog(JFrame frame) super(frame); imageLabel = new JLabel(); getContentPane().add(imageLabel); this.addWindowListener(new WindowAdapter() public void windowClosing(WindowEv

7、ent e) hide (); ); this.setSize(200, 200); public void setImage(ImageIcon icon) imageLabel. _(icon); 三、综合应用题( 30分) 3 下面是一个 Applet程序,其功能是建立 2个文本区域,一个为编辑区,一个为只读区;建立 2个按钮,一个实现将编辑区中被鼠标选定的文本内容拷贝到只读区中,一个实现将只读区的全部文本内容清空。请改正程序中的错误 (有下划线的语句 ),使程序能输出正确的结果。 注意:不改动程序的结构,不得增行或删行。 程序运行结果如下: import java.awt.*; imp

8、ort java.applet.*; /* applet code=“ex6_3.class“ width=800 height=400 /applet */ public class ex6_3 extends Applet private Button okBtn, clearBtn; private String strMessage; private TextArea tAreal, tArea2; public void init() strMessage = “Hello! Welcome to the test! n“ + “This is the NCR Examination

9、 n“ + “Wish you good luck!“; tAreal = new TextArea( 10, 25 ); tAreal.setText(strMessage); tArea2 = new TextArea( 10, 25 ); tArea2.setEditable( true ); okBtn = new Button( “Copy“ ); clearBtn = new Button( “Clear“ ); add( tArea1 ); add( tArea2 ); add( okBtn ); add( clearBtn ); public boolean action(

10、Event e, Object o ) if( e.target = okBtn ) tAreal.setText(tArea2.getSelectedText() ); else if( e.target = clearBtn ) tAreal.setText( “ “ ); return true; ex6_3. html HTML HEAD TITLE ex6_3 /TITLE /HEAD BODY applet code=“ex6_3.class“width=800 height=400 /applet /BODY /HTML 国家二级( JAVA)机试模拟试卷 109答案与解析 一、

11、基本操作题( 30分) 1 【正确答案】 String args result*=n-; while(n =1); 【试题解析】 本题主要考查 main()主方法的使用、 while循环语句的用法。解答本题的关键是熟练掌握 main()主方法的使用、 while循环语句的用法。 在本题中,String args的作用是声明字符数组 args, result*=n-;语句的作用是获得 n的阶乘并赋值给变量 result。 二、简单应用题( 40分) 2 【正确答案】 new ImageIcon(fileName) setIcon 【试题解析】 本题是将图片作为图标显示到构件中。 ImageDia

12、log是程序自定义的一个对话框类,在其中添加了一个 JLabel对象 “imageLabel”, setImage方法可以将名为 “icon”的图片添加到 imageLabel中,显示到 界面上, ImageDialog对话框的标题为图片文件的文件名。 actionPerformed方法相应 “浏览图片 ”按钮对应的事件。按下按钮以后,首先获得用户输入的文件名,以及对应的图片,然后生成 ImageDialog的对象,调用其中的 setImage方法把图片显示出来。 第 1个空是获得根据文件名获得图片。直接根据文件名新建一个 ImageIcon对象。 第 2个空考查构件添加图标的方法。 JLab

13、el添加图标的方法是 setIcon()。 三、综合应用题( 30分) 3 【正确答案】 tArea2.setEditable( false) tArea2.setText(tAreal.getSelectedText() tArea2.setText( “ “ ) 【试题解析】 本题主要考查 Applet窗口、其事件处理机制以及对文本区域的相关操作。解题关键是熟悉 TextArea的基本方法,如 setEditable()方法就是用来确定不用的编辑模式的一个重要的方法,并且需要明确题目要求的 2个文本区域的区别和联系,根据不同的事件,来对这两个文本区域进行操作。本题中,第 1个空,将第 2个文本区域 tArea2的编辑模 式设定为只读,注意参数为 false,因为默认的编辑模式设定为可编辑的,用 true表示,所以参数应该是 false;第 2个空,响应点击 Copy按钮事件的语句应该将第 1个文本区 tArea1的被选择的文本内容取出放入第二个文本区 tArea2中;第 2个空,响应点击 Clear按钮事件的语句应该将第 2个文本区 tArea2中的所有文本内容清空。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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