【计算机类职业资格】(A)二级JAVA笔试-10及答案解析.doc
《【计算机类职业资格】(A)二级JAVA笔试-10及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】(A)二级JAVA笔试-10及答案解析.doc(6页珍藏版)》请在麦多课文档分享上搜索。
1、(A)二级 JAVA 笔试-10 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.本题定义了一个长度为 10 的 boolean 型数组,并给数组元素赋值,要求如果数组元素下标为奇数,则数组元素值为 false,否则为 true。public class java1public static void main(String args)boolean b=_;for(int i=0; i10; i+)if(_)bi=false;else_;for(int i=0; i10; i+)System. out. print(“b“+i+“=“+
2、bi+“,“);(分数:30.00)填空项 1:_二、简单应用题(总题数:1,分数:30.00)2.本题是一个 Applet,它的功能是在窗口上添加 1212 个标签,并且横向和纵向标签的颜色为黑白相间。import java. applet. * ;import java. awt. * ;import java. awt. event. * ;public class java2extends AppletGridLayout grid;public void init()grid=new GridLayout(12,12);setLayout(grid);Label_=new Label
3、1212;for(int i=0; i12; i+)for(intj=0; j12; j+)labelij=_;if(i+j)%2=0)labelij. setBackground(Color. black);elselabelij. setBackground(Color. white);add(labelEij);(分数:30.00)填空项 1:_三、综合应用题(总题数:1,分数:40.00)3.本题的功能是获得系统剪贴板中的内容。窗口中有一个菜单“Edit”和一个文本域,“Edit”中有菜单项“Cut”、“Copy”和“Paste”,在文本域中输入内容,可以通过菜单进行剪切、复制和粘贴操
4、作,如果系统剪贴板为空,又做粘贴操作的话,则设置文本域中背景颜色为红色,并显示错误信息。import java. awt. * ;import java. io. * ;import java. awt. datatransfer. * ;import java. awt. event. * ;class java3 extends Frame implements ActionListener,ClipboardOwner TextArea textArea=new TextArea();java3()super(“java3“);addWindowListener(new WindowAd
5、apter()public void windowClosing(WindowEvent e)System. exit(0);/);MenuBar mb=new MenuBar();Menu m=new Menu(“Edit“);setLayout(new BorderLayout();add(“Center“, textArea);m. add(“Cut“);m. add(“Copy“);m. add(“Paste“);mb. add(m);setMenuBar(this);for (int i=0; im. getItemCount(); i+)m. item(i). addActionL
6、istener(this);setSize(300,300);show();public void actionPerformed(ActionEvent evt)if (“Paste“. equals(evt, getActionCommand()boolean error=true;Transferable t=getToolkit(). getSystemClipboard(). getContents(this);tryif(t ! =null textArea. setForeground(Color, black);textArea. replaceRange(String) t.
7、 getTransferData(DataFlavor. stringFlavor),textArea. getSelectionStart(),textArea. getSelectionEnd();error=false;catch(UnsupportedFlavorException e)catch(IOException e)if (error)textArea. setBackground(Color, red);textArea. setForeground(Color, white);textArea. repaint();textArea. setText(“ERROR:/nE
8、ither the clipboard“+“ is empty or the contents is not a string.“);else if (“Copy“. equals(evt. getActionCommand()setContents();else if (“Cut“. equals (evt. getActionCommand()setContents ();textArea. replaceRange(“, textArea. getSelectionStart(), textArea. getSelectionEnd();void setContents()S=textA
9、rea. getSelectedText();StringSelection contents=new StringSelection(s);getToolkit(). getSystemClipboard(). setContents(contents, this);public void lostOwnership (Clipboard clipboard, Transferable contents)System. out. println(“lost ownership“);public static void main(String args)new java3();(分数:40.0
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 JAVA 笔试 10 答案 解析 DOC
