【计算机类职业资格】(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 EN ISO 15318-2000 Pulp paper and board - Determination of 7 specified polychlorinated biphenyls (PCB)《纸浆、纸和纸板 对7个指定的聚氯联苯(PCB)的测定》.pdf BS EN ISO 15318-2000 Pulp paper and board - Determination of 7 specified polychlorinated biphenyls (PCB)《纸浆、纸和纸板 对7个指定的聚氯联苯(PCB)的测定》.pdf
  • BS EN ISO 15320-2011 Pulp paper and board Determination of pentachlorophenol in an aqueous extract《纸浆、纸和纸板 水提出物中五氯酚的测定》.pdf BS EN ISO 15320-2011 Pulp paper and board Determination of pentachlorophenol in an aqueous extract《纸浆、纸和纸板 水提出物中五氯酚的测定》.pdf
  • BS EN ISO 15329-2006 Corrosion of metals and alloys - Anodic test for evaluation of intergranular corrosion susceptibility of heat-treatable aluminium alloys《金属和合金的腐蚀 可热处理的铝合金粒间腐蚀敏.pdf BS EN ISO 15329-2006 Corrosion of metals and alloys - Anodic test for evaluation of intergranular corrosion susceptibility of heat-treatable aluminium alloys《金属和合金的腐蚀 可热处理的铝合金粒间腐蚀敏.pdf
  • BS EN ISO 15330-1999 Fasteners - Preloading test for the detection of hydrogen embrittlement - Parallel bearing surface method《紧固件 检查氢脆性用预载荷试验 平行支承面法》.pdf BS EN ISO 15330-1999 Fasteners - Preloading test for the detection of hydrogen embrittlement - Parallel bearing surface method《紧固件 检查氢脆性用预载荷试验 平行支承面法》.pdf
  • BS EN ISO 15349-2-2003 Unalloyed steel - Determination of low carbon content - Infrared absorption method after combustion in an induction furnace (with preheating)《非合金钢 低碳含量的测定 (预.pdf BS EN ISO 15349-2-2003 Unalloyed steel - Determination of low carbon content - Infrared absorption method after combustion in an induction furnace (with preheating)《非合金钢 低碳含量的测定 (预.pdf
  • BS EN ISO 15350-2010 Steel and iron - Determination of total carbon and sulfur content - Infrared absorption method after combustion in an induction furnace (routine method)《钢铁 总碳量.pdf BS EN ISO 15350-2010 Steel and iron - Determination of total carbon and sulfur content - Infrared absorption method after combustion in an induction furnace (routine method)《钢铁 总碳量.pdf
  • BS EN ISO 15351-2010 Steel and iron - Determination of nitrogen content - Thermal conductimetric method after fusion in a current of inert gas (Routine method)《钢铁 氮含量的测定 惰性气体熔融后热电导.pdf BS EN ISO 15351-2010 Steel and iron - Determination of nitrogen content - Thermal conductimetric method after fusion in a current of inert gas (Routine method)《钢铁 氮含量的测定 惰性气体熔融后热电导.pdf
  • BS EN ISO 15367-1-2003 Lasers and laser-related equipment - Test methods for determination of the shape of a laser beam wavefront - Terminology and fundamental aspects《激光和激光相关设备 测定.pdf BS EN ISO 15367-1-2003 Lasers and laser-related equipment - Test methods for determination of the shape of a laser beam wavefront - Terminology and fundamental aspects《激光和激光相关设备 测定.pdf
  • BS EN ISO 15367-2-2006 Lasers and laser-related equipment - Test methods for determination of the shape of a laser beam wavefront - Shack-Hartmann sensors《激光和激光相关设备 激光束波前形状测定试验方法 哈.pdf BS EN ISO 15367-2-2006 Lasers and laser-related equipment - Test methods for determination of the shape of a laser beam wavefront - Shack-Hartmann sensors《激光和激光相关设备 激光束波前形状测定试验方法 哈.pdf
  • 相关搜索

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

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