【计算机类职业资格】(A)二级JAVA笔试-4及答案解析.doc

上传人:花仙子 文档编号:1317784 上传时间:2019-10-17 格式:DOC 页数:8 大小:40KB
下载 相关 举报
【计算机类职业资格】(A)二级JAVA笔试-4及答案解析.doc_第1页
第1页 / 共8页
【计算机类职业资格】(A)二级JAVA笔试-4及答案解析.doc_第2页
第2页 / 共8页
【计算机类职业资格】(A)二级JAVA笔试-4及答案解析.doc_第3页
第3页 / 共8页
【计算机类职业资格】(A)二级JAVA笔试-4及答案解析.doc_第4页
第4页 / 共8页
【计算机类职业资格】(A)二级JAVA笔试-4及答案解析.doc_第5页
第5页 / 共8页
点击查看更多>>
资源描述

1、A)二级 JAVA 笔试-4 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.本题中定义了长度为 20 的一维整型数组 a,并将数组元素的下标值赋给数组元素,最后打印输出数组中下标为奇数的元素。public class java1public static void main(String args)int a=_;int i;for(_; i+)ai=i;for(i=0; i20; i+)if(_)System. out. print(“a“+i+“=“+ai+“,“);(分数:30.00)填空项 1:_二、简单应用题(总题数:1,分

2、数:30.00)2.本题中定义了一个树型的通信录,窗口左侧是一个树,右侧是一个文本域,单击树的结点,则在右侧文本域中显示相关信息,如果单击的是树结点,则显示对应名字的电话信息。import javax. swing. * ;import javax. swing. tree. * ;import java. awt. * ;import java. awt. event. * ;import javax. swing. event. * ;class Mytree2 extends JFrame_JTree tree=null; JTextArea text=new JTextArea(20,

3、20);Mytree2()Container con=getContentPane();DefauhMutableTreeNode root=new DefauhMutableTreeNode (“同学通信录“);DefaultMutableTreeNode t1=new DefauhMutableTreeNode(“大学同学“);DefaultMutableTreeNode t2=new DefaultMutableTreeNode(“研究生同学“);DefaultMutableTreeNode t1_1=new DefauhMutableTreeNode(“陈艳“);DefauhMutab

4、leTreeNode t1_2=new DefaultMutableTreeNode(“李小永“);DefauhMutableTreeNode t2_1=new DefaultMutableTreeNode(“王小小“);DefaultMutableTreeNode t2_2=new DefaultMutableTreeNode(“董小“);setTitle(“java2“);root. add(t1); root. add(t2);t1. add(t1_1); t1, add(t1_2); t2. add(t2_1); t2. add(t2_2);tree=new JTree(root);J

5、ScrollPane scrollpane=new JScrollPane(text);JSplitPane splitpane=new JSplitPane(JSplitPane. HORIZONTAL_SPLIT,true, tree, scrollpane);tree. addTreeSelectionListener(this);con. add(splitpane);addWindowListener( new WindowAdapter()public void windowClosing(WindowEvent e)System. exit(0););setVisible(tru

6、e); setBounds(70,80,200,300);public void valueChanged(TreeSelectionEvent e)if(e, getSource()=tree)DefaultMutableTreeNode node=(DefaultMutableTreeNode) tree. getLastSelectedPathComponent();if(node. isLeaf()String str=_;if(str. equals(“陈艳“)text. setText(str+“:联系电话: 0411-4209876“);else if(str. equals(“

7、李小永“)text. setText (str+“:联系电话: 010 -62789876“);else if(str. equals(“王小小“)text. setText (str+“: 联系电话: 0430-63596677“);else if(str. equals(“董小“)text. setText(str +“: 联系电话: 020-85192789“);elsetext. setText(node. getUserObject(). toString();public class java2public static void main(String args)Mytree2

8、win=new Mytree2(); win. pack();(分数:30.00)填空项 1:_三、综合应用题(总题数:1,分数:40.00)3.本题中,鼠标在窗口中单击一下,就在单击的位置生成一个小矩形,如果在小矩形上双击鼠标左键,则删除小矩形。import java. awt. * ;import java. awt. event. * ;import javax. swing. * ;class MousePanel extends JPanel extends MouseMotionListenerpublic MousePanel()addMouseListener(new Mous

9、eAdapter()public void mousePressed(MouseEvent evt)int x=evt. getX();int y=evt. getY();current=find(x, y);if(current0)add(x, y);public void mouseClicked(MouseEvent evt)int x=evt. getX();int y=evt. getY();if(evt. getClickCount()=2)remove(current););addMouseMotionListener(this);public void paintCompone

10、nt(Graphics g)(super. paintComponent();for (int i=0; insquares; i+)draw(g, i);public int find(int x, int y)for(int i=0; insquares; i+)if (squaresi. x-SQUARELENGTH/2=xreturn-1;public void draw(Graphics g, int i)g. drawRect(squaresi. x-SQUARELENGTH/2,squaresi. y-SQUARELENGTH/2,SQUARELENGTH,SQUARELENGT

11、H);public void add(int x, int y)if(nsquaresMAXNSQUARES)squaresnsquares=new Point(x, y);current=nsquares;nsquares+;repaint();public void remove(int n)if(n0|n=nsquares) return;nsquares-;squaresn=squaresnsquares;if(current=n) current=-1;repaint();public void mouseMoved(MouseEvent evt)public void mouseD

12、ragged(MouseEvent evt)private static final int SQUARELENGTH=10;private static final int MAXNSQUARES=100;private Point squares=new Point MAXNSQUARES;private int nsquares=0;private int current=-1;class MouseFrame extends JFramepublic MouseFrame()setTitle(“java3“);setSize(300,200);addWindowListener(new

13、 WindowAdapter()public void windowClosing(WindowEvent e)System. exit(0););Container contentPane=getContentPane();contentPane. add (MousePanel();public class java3public static void main(String args)JFrame frame=new MouseFrame();frame. show();(分数:40.00)填空项 1:_(A)二级 JAVA 笔试-4 答案解析(总分:100.00,做题时间:90 分钟

14、)一、基本操作题(总题数:1,分数:30.00)1.本题中定义了长度为 20 的一维整型数组 a,并将数组元素的下标值赋给数组元素,最后打印输出数组中下标为奇数的元素。public class java1public static void main(String args)int a=_;int i;for(_; i+)ai=i;for(i=0; i20; i+)if(_)System. out. print(“a“+i+“=“+ai+“,“);(分数:30.00)填空项 1:_ (正确答案:第 1 处:new int20第 2 处:i=0; i20第 3 处:i%2!=0)解析:解析 第

15、1 处定义了长度为 20 的一维整型数组 a;第 2 处的 for 循环将数组元素的下标值赋给数组元素;第 3 处判断数组各个元素下标是否为奇数。二、简单应用题(总题数:1,分数:30.00)2.本题中定义了一个树型的通信录,窗口左侧是一个树,右侧是一个文本域,单击树的结点,则在右侧文本域中显示相关信息,如果单击的是树结点,则显示对应名字的电话信息。import javax. swing. * ;import javax. swing. tree. * ;import java. awt. * ;import java. awt. event. * ;import javax. swing.

16、event. * ;class Mytree2 extends JFrame_JTree tree=null; JTextArea text=new JTextArea(20,20);Mytree2()Container con=getContentPane();DefauhMutableTreeNode root=new DefauhMutableTreeNode (“同学通信录“);DefaultMutableTreeNode t1=new DefauhMutableTreeNode(“大学同学“);DefaultMutableTreeNode t2=new DefaultMutableT

17、reeNode(“研究生同学“);DefaultMutableTreeNode t1_1=new DefauhMutableTreeNode(“陈艳“);DefauhMutableTreeNode t1_2=new DefaultMutableTreeNode(“李小永“);DefauhMutableTreeNode t2_1=new DefaultMutableTreeNode(“王小小“);DefaultMutableTreeNode t2_2=new DefaultMutableTreeNode(“董小“);setTitle(“java2“);root. add(t1); root. a

18、dd(t2);t1. add(t1_1); t1, add(t1_2); t2. add(t2_1); t2. add(t2_2);tree=new JTree(root);JScrollPane scrollpane=new JScrollPane(text);JSplitPane splitpane=new JSplitPane(JSplitPane. HORIZONTAL_SPLIT,true, tree, scrollpane);tree. addTreeSelectionListener(this);con. add(splitpane);addWindowListener( new

19、 WindowAdapter()public void windowClosing(WindowEvent e)System. exit(0););setVisible(true); setBounds(70,80,200,300);public void valueChanged(TreeSelectionEvent e)if(e, getSource()=tree)DefaultMutableTreeNode node=(DefaultMutableTreeNode) tree. getLastSelectedPathComponent();if(node. isLeaf()String

20、str=_;if(str. equals(“陈艳“)text. setText(str+“:联系电话: 0411-4209876“);else if(str. equals(“李小永“)text. setText (str+“:联系电话: 010 -62789876“);else if(str. equals(“王小小“)text. setText (str+“: 联系电话: 0430-63596677“);else if(str. equals(“董小“)text. setText(str +“: 联系电话: 020-85192789“);elsetext. setText(node. ge

21、tUserObject(). toString();public class java2public static void main(String args)Mytree2 win=new Mytree2(); win. pack();(分数:30.00)填空项 1:_ (正确答案:第 1 处:implements TreeSelectionListener第 2 处:node. toString())解析:解析 第 1 处实现了一个 JTree 的监听器接口;第 2 处将 node 转换成 String 型。三、综合应用题(总题数:1,分数:40.00)3.本题中,鼠标在窗口中单击一下,就

22、在单击的位置生成一个小矩形,如果在小矩形上双击鼠标左键,则删除小矩形。import java. awt. * ;import java. awt. event. * ;import javax. swing. * ;class MousePanel extends JPanel extends MouseMotionListenerpublic MousePanel()addMouseListener(new MouseAdapter()public void mousePressed(MouseEvent evt)int x=evt. getX();int y=evt. getY();cur

23、rent=find(x, y);if(current0)add(x, y);public void mouseClicked(MouseEvent evt)int x=evt. getX();int y=evt. getY();if(evt. getClickCount()=2)remove(current););addMouseMotionListener(this);public void paintComponent(Graphics g)(super. paintComponent();for (int i=0; insquares; i+)draw(g, i);public int

24、find(int x, int y)for(int i=0; insquares; i+)if (squaresi. x-SQUARELENGTH/2=xreturn-1;public void draw(Graphics g, int i)g. drawRect(squaresi. x-SQUARELENGTH/2,squaresi. y-SQUARELENGTH/2,SQUARELENGTH,SQUARELENGTH);public void add(int x, int y)if(nsquaresMAXNSQUARES)squaresnsquares=new Point(x, y);cu

25、rrent=nsquares;nsquares+;repaint();public void remove(int n)if(n0|n=nsquares) return;nsquares-;squaresn=squaresnsquares;if(current=n) current=-1;repaint();public void mouseMoved(MouseEvent evt)public void mouseDragged(MouseEvent evt)private static final int SQUARELENGTH=10;private static final int M

26、AXNSQUARES=100;private Point squares=new Point MAXNSQUARES;private int nsquares=0;private int current=-1;class MouseFrame extends JFramepublic MouseFrame()setTitle(“java3“);setSize(300,200);addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System. exit(0););Container conte

27、ntPane=getContentPane();contentPane. add (MousePanel();public class java3public static void main(String args)JFrame frame=new MouseFrame();frame. show();(分数:40.00)填空项 1:_ (正确答案:第 1 处:extends JPanel implements MouseMotionListener第 2 处:super. paintComponent(g)第 3 处:eontentPane. add(new MousePanel())解析:解析 第 1 处是继承 Jpanel 实现鼠标移动监听器接口;第 2 处以 g 为参数重新绘制组件;第 3 处在 contentPane 内容面板中添加一个 MousePanel 鼠标面板。

展开阅读全文
相关资源
猜你喜欢
  • BS PD ISO TR 4191-2014 Plastics piping systems for water supply Unplasticized poly(vinyl chloride)(PVC-U) and oriented PVC-U (PVC-O) Guidance for installation《供水用塑料管系统 未增塑聚氯乙烯(PVC-U)和定向PVC-U (PVC-.pdf BS PD ISO TR 4191-2014 Plastics piping systems for water supply Unplasticized poly(vinyl chloride)(PVC-U) and oriented PVC-U (PVC-O) Guidance for installation《供水用塑料管系统 未增塑聚氯乙烯(PVC-U)和定向PVC-U (PVC-.pdf
  • BS PD ISO TS 13399-305-2017 Cutting tool data representation and exchange Creation and exchange of 3D models Modular tooling systems with adjustable cartridges for boring《切削工具数据表示和交换 三维模型的创造和交流.pdf BS PD ISO TS 13399-305-2017 Cutting tool data representation and exchange Creation and exchange of 3D models Modular tooling systems with adjustable cartridges for boring《切削工具数据表示和交换 三维模型的创造和交流.pdf
  • BS PD ISO TS 19337-2016 Nanotechnologies Characteristics of working suspensions of nano-objects for $ii$in $iv$ii$it$ir$io assays to evaluate inherent nano-object toxi city《纳米技术 评估纳米物体固有毒性的体外试验所.pdf BS PD ISO TS 19337-2016 Nanotechnologies Characteristics of working suspensions of nano-objects for $ii$in $iv$ii$it$ir$io assays to evaluate inherent nano-object toxi city《纳米技术 评估纳米物体固有毒性的体外试验所.pdf
  • BS PD ISO TS 21219-2-2014 Intelligent transport systems Traffic and travel information (TTI) via transport protocol experts group generation 2 (TPEG2) UML modelling rules《智能运输系统 利用第二代传输协议专家组 (TPEG.pdf BS PD ISO TS 21219-2-2014 Intelligent transport systems Traffic and travel information (TTI) via transport protocol experts group generation 2 (TPEG2) UML modelling rules《智能运输系统 利用第二代传输协议专家组 (TPEG.pdf
  • BS PD ISO TS 28560-4-2014 Information and documentation RFID in libraries Encoding of data elements based on rules from ISO IEC 15962 in an RFID tag with partitioned memory《信息与文献 图书馆中应用的无线射频识别技术.pdf BS PD ISO TS 28560-4-2014 Information and documentation RFID in libraries Encoding of data elements based on rules from ISO IEC 15962 in an RFID tag with partitioned memory《信息与文献 图书馆中应用的无线射频识别技术.pdf
  • BS S 150-1975 Specification for chromium-molybdenum-vanadium-niobium heat-resisting steel billets bars forgings and parts (930-1080 MPa) (Cr 10 5 Mo 0 6 V 0 2 Nb 0 3)《铬-钼-钒-铌-耐热钢坯、棒材、锻件及零件规范(930-.pdf BS S 150-1975 Specification for chromium-molybdenum-vanadium-niobium heat-resisting steel billets bars forgings and parts (930-1080 MPa) (Cr 10 5 Mo 0 6 V 0 2 Nb 0 3)《铬-钼-钒-铌-耐热钢坯、棒材、锻件及零件规范(930-.pdf
  • BS PD ISO IEC TR 20000-12-2016 Information technology Service management Guidance on the relationship between ISO IEC 20000-1 2011 and service management frameworks CMMI-SVC 《信息技术 .pdf BS PD ISO IEC TR 20000-12-2016 Information technology Service management Guidance on the relationship between ISO IEC 20000-1 2011 and service management frameworks CMMI-SVC 《信息技术 .pdf
  • BS PD ISO IEC TR 20007-2014 Information technology Cultural and linguistic interoperability Definitions and relationship between symbols icons animated icons pictograms characters .pdf BS PD ISO IEC TR 20007-2014 Information technology Cultural and linguistic interoperability Definitions and relationship between symbols icons animated icons pictograms characters .pdf
  • BS PD ISO IEC TR 29110-5-1-3-2017 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Software engineering Management and engineering guide Generic p.pdf BS PD ISO IEC TR 29110-5-1-3-2017 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Software engineering Management and engineering guide Generic p.pdf
  • 相关搜索

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

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