【计算机类职业资格】二级JAVA机试-89及答案解析.doc

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

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

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

3、tentPane();DefaultMutableTreeNode root=new DefauhMutableTreeNode(“同学通信录“);DefaultMutableTreeNode t1=new DefauhMutableTreeNode(“大学同学“);DefaultMutableTreeNode t2=new DefaultMutableTreeNode(“研究生同学“);DefaultMutableTreeNode t1_1=new DefauhMutableTreeNode(“陈艳“);DefaultMutableTreeNode t1_2=new DefauhMutabl

4、eTreeNode(“李小永“);DefaultMutableTreeNode t2_1=new DefauhMutableTreeNode(“王小小“);DefaultMutableTreeNode t2_2=new DefauhMutableTreeNode(“董小“);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 ITree(root);JScrollPane scrollpane=new JScrollPane(text);

5、JSplitPane splitpane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,tree,scrollpane);tree.addTreeSelectionListener(this);con.add(splitpane);addWindowListener(Flew WindowAdapter()public void windowClosing(WindowEvent e)System.ext(0););setVisible(true);setBounds(70,80,200,300);public void valueChange

6、d(TreeSelectionEvent e)if(e.getSource()=tree)DefaultMutableTreeNode node=(DefauhMutableTreeNode)tree.getLastSelectedPathComponent();if(node.isLeaf()String str=_;if(str.equals(“陈艳“)text.setText(str+“:联系电话:0411-4209876“);else if(str.equals(“李小永“)text.setText(str+“:联系电话:010-62789876“);else if(str.equal

7、s(“王小小“)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 win=new Mytree2();win.pack();(分数:40.00)_三、综合应用题(总题数:1,分数:30.00)3.本题中,鼠标在窗口中单击

8、一下,就在单击的位置生成一个小矩形,如果在小矩形上双击鼠标左键,则删除小矩形。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();current=fin

9、d(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););addMouseMorionListener(this);public void paintComponent(Graphics g)(super.paintComponent();for(int i=0;insquares;i+)draw(g,i);public int find(int x,int y)f

10、or(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);current=nsquares;nsquares+;repa

11、int();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 MAXNSQUARES=100;private Point

12、squares=new PointMAXNSQUARES;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 contentPane=getContentPane();content

13、Pane.add(MousePanel();public class java3public static void main(Stringargs)JFrame frame=new MouseFrame();frame.show();(分数:30.00)_二级 JAVA 机试-89 答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.本题中定义了长度为 20 的一维整型数组 a,并将数组元素的下标值赋给数组元素,最后打印输出数组中下标为奇数的元素。public class java1(public static void main(Strin

14、gargs)int a=_;int i;for(_;i+)ai=i;for(i=0;i20;i+)if(_)System.out.print(“a“+i+“=“+ai+“,“);(分数:30.00)_正确答案:(第 1 处:new int20第 2 处:i=0;i20第 3 处:i%2! =0)解析:解析 第 1 处定义了长度为 20 的一维整型数组 a;第 2 处的 for 循环将数组元素的下标值赋给数组元素;第 3 处判断数组各个元素下标是否为奇数。二、简单应用题(总题数:1,分数:40.00)2.本题中定义了一个树型的通信录,窗口左侧是一个树,右侧是一个文本域,单击树的结点,则在右侧文本

15、域中显示相关信息,如果单击的是树结点,则显示对应名字的电话信息。import javax.swing.*;import javax.swing.tree.*;import java.awt.*;import java.awt.event.*;import javax.swing.event.*;class Mytree2 extends JFrameJTree tree=null;JTextArea text=new JTextArea(20,20);Mytree2()Container con=getContentPane();DefaultMutableTreeNode root=new

16、DefauhMutableTreeNode(“同学通信录“);DefaultMutableTreeNode t1=new DefauhMutableTreeNode(“大学同学“);DefaultMutableTreeNode t2=new DefaultMutableTreeNode(“研究生同学“);DefaultMutableTreeNode t1_1=new DefauhMutableTreeNode(“陈艳“);DefaultMutableTreeNode t1_2=new DefauhMutableTreeNode(“李小永“);DefaultMutableTreeNode t2_

17、1=new DefauhMutableTreeNode(“王小小“);DefaultMutableTreeNode t2_2=new DefauhMutableTreeNode(“董小“);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 ITree(root);JScrollPane scrollpane=new JScrollPane(text);JSplitPane splitpane=new JSplitPane(JSplitP

18、ane.HORIZONTAL_SPLIT,true,tree,scrollpane);tree.addTreeSelectionListener(this);con.add(splitpane);addWindowListener(Flew WindowAdapter()public void windowClosing(WindowEvent e)System.ext(0););setVisible(true);setBounds(70,80,200,300);public void valueChanged(TreeSelectionEvent e)if(e.getSource()=tre

19、e)DefaultMutableTreeNode node=(DefauhMutableTreeNode)tree.getLastSelectedPathComponent();if(node.isLeaf()String 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-635966

20、77“);else if(str.equals(“董小“)text.setText(str+“:联系电话:020-85192789“);)elsetext.setText(node.getUserObject().toString();public class java2public static void main(String args)Mytree2 win=new Mytree2();win.pack();(分数:40.00)_正确答案:(第 1 处:implements TreeSelectionListener第 2 处:node.toString()解析:解析 第 1 处实现了一

21、个 JTree 的监听器接口;第 2 处将 node 转换成 String 型。三、综合应用题(总题数:1,分数:30.00)3.本题中,鼠标在窗口中单击一下,就在单击的位置生成一个小矩形,如果在小矩形上双击鼠标左键,则删除小矩形。import java.awt.*;import java.awt.event.*;import javax.swing.*;class MousePanel extends JPanel extends MouseMotionListenerpublic MousePanel()addMouseListener(new MouseAdapter()public v

22、oid 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););addMouseMorionListener(this);public void paintComponent(Graphics g)(super.pain

23、tComponent();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,SQUARELENGTH);public void add(int x,int y)if(nsqua

24、resMAXNSQUARES)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 mouseDragged(MouseEvent evt)private static fina

25、l int SQUARELENGTH=10;private static final int MAXNSQUARES=100;private Point squares=new PointMAXNSQUARES;private int nsquares=0;private int current=-1;class MouseFrame extends JFramepublic MouseFrame()setTitle(“java3“);setSize(300,200);addWindowListener(new WindowAdapter()public void windowClosing(

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

展开阅读全文
相关资源
猜你喜欢
  • NF C32-335-2003 Insulated cables and flexible cords for installations - Heating cables without mechanical protection and reduced cross sectional area 《装置用绝缘电缆和软线 无机械保护和减径横截面积的加热电缆》.pdf NF C32-335-2003 Insulated cables and flexible cords for installations - Heating cables without mechanical protection and reduced cross sectional area 《装置用绝缘电缆和软线 无机械保护和减径横截面积的加热电缆》.pdf
  • NF C32-500-1998 Cables for signs and luminous-discharge-tube installations operating from no-load rated output voltage exceeding 1 kV but not exceeding 10 kV 《无负荷额定输出电压1KV至10KV的信号和.pdf NF C32-500-1998 Cables for signs and luminous-discharge-tube installations operating from no-load rated output voltage exceeding 1 kV but not exceeding 10 kV 《无负荷额定输出电压1KV至10KV的信号和.pdf
  • NF C32-902-1998 Insulated cables and cords for installations Power cable accessories intended for industry for rated voltage 0 6 1(1 2) kV Test methods and test requirements 《设备用绝缘.pdf NF C32-902-1998 Insulated cables and cords for installations Power cable accessories intended for industry for rated voltage 0 6 1(1 2) kV Test methods and test requirements 《设备用绝缘.pdf
  • NF C33-001-1993 Insulated cables and their accessories for power systems-electrical accessories for synthetic insulated cables with rated voltages from 1 8 3(3 6)kV up to 18 30(36).pdf NF C33-001-1993 Insulated cables and their accessories for power systems-electrical accessories for synthetic insulated cables with rated voltages from 1 8 3(3 6)kV up to 18 30(36).pdf
  • NF C33-005-2005 Test methods for accessories for power cables with rated voltages from 6 kV (Um = 7 2 kV) up to 36 kV (Um = 42 kV) 《额定电压6-36kV(Um=7 2-42kV)的电力电缆附件的试验方法》.pdf NF C33-005-2005 Test methods for accessories for power cables with rated voltages from 6 kV (Um = 7 2 kV) up to 36 kV (Um = 42 kV) 《额定电压6-36kV(Um=7 2-42kV)的电力电缆附件的试验方法》.pdf
  • NF C33-009-1-2008 Electric cables - Accessories - Material characterisation - Part 1  fingerprinting and type tests for resinous compounds 《电缆 配件 材料特性 第1部分 树脂化合物用指纹识别和类型试验》.pdf NF C33-009-1-2008 Electric cables - Accessories - Material characterisation - Part 1 fingerprinting and type tests for resinous compounds 《电缆 配件 材料特性 第1部分 树脂化合物用指纹识别和类型试验》.pdf
  • NF C33-009-2-2008 Electric cables - Accessories - Material characterization - Part 2  fingerprinting and type tests for heat shrinkable components for low voltage applications 《电缆 .pdf NF C33-009-2-2008 Electric cables - Accessories - Material characterization - Part 2 fingerprinting and type tests for heat shrinkable components for low voltage applications 《电缆 .pdf
  • NF C33-010-1993 Insulated cables and their accessories for power systems - Filling compounds polymerisable at ambient temperature cast or injected for cable accessories of rated vo.pdf NF C33-010-1993 Insulated cables and their accessories for power systems - Filling compounds polymerisable at ambient temperature cast or injected for cable accessories of rated vo.pdf
  • NF C33-014-1995 Insulated cables and their accessories for power systems Screen tape for single-core cables of rated voltages from 6 10 (12) kv to 18 30 (36) kv 《电力系统用绝缘电缆及其附件 额定电压.pdf NF C33-014-1995 Insulated cables and their accessories for power systems Screen tape for single-core cables of rated voltages from 6 10 (12) kv to 18 30 (36) kv 《电力系统用绝缘电缆及其附件 额定电压.pdf
  • 相关搜索

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

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