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

上传人:diecharacter305 文档编号:1338319 上传时间:2019-10-17 格式:DOC 页数:3 大小:35.50KB
下载 相关 举报
【计算机类职业资格】计算机二级JAVA-32及答案解析.doc_第1页
第1页 / 共3页
【计算机类职业资格】计算机二级JAVA-32及答案解析.doc_第2页
第2页 / 共3页
【计算机类职业资格】计算机二级JAVA-32及答案解析.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

1、计算机二级 JAVA-32及答案解析(总分:100.00,做题时间:90 分钟)一、B1基本操作题/B(总题数: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)_二、B2简单应用题/B(总题数:

2、1,分数:40.00)2.本题中,窗口的背景色为系统桌面的颜色,在窗口中分别画空心和实心的黑色矩形、深灰色圆角矩形和浅灰色椭圆形,并且画白色粗体的“欢迎学习 Java!”字符串。 import java.awt.*; import javax.swing.*; public class java2 public static void main(Stringargs) FillFrame frame=new FillFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); class FillFra

3、me extends JFrame public FillFrame() setTitle(“java2“); setSize(WIDTH,HEIGHT); FillPanel panel=new FillPanel(); panel.setBackround(SystemColor.desktop); Container contentPane=getContentPane(); contentPane.add(panel); public static final int WIDTH=400; public static final int HEIGHT=250; class FillPa

4、nel extends JPanel public void paintComponent(Graphics g) _; g.setColor(new Color(10,10,10); g.drawRect(10,10,100,30); g.setColor(new Color(100,100,100); g.drawRoundRect(150,10,100,30,15,15); g.setColor(new Color(150,150,150); g.drawOval(280,10,80,30); g.setColor(new Color(10,10,10); g.fillRect(10,1

5、10,100,30); g.setColor(new Color(100,100,100); g.fillRoundRect(150,110,100,30,15,15); g.setColor(new Color(150,150,150); g.fillOval(280,110,80,30); g.setColor(Color.white); Font f=new Font(“宋体“,_,20); g.setFont(f); g.drawstring(“欢迎学习 Java!“,150,200); (分数:40.00)_三、B3综合应用题/B(总题数:1,分数:30.00)3.本题的功能是监听键

6、盘键的敲击,并显示在窗口中。 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class java3 Uextends JFrame extends KeyListener/U private String linel=“,line2=“; private String line3=“; private JTextArea textArea; public java3() super(“java3“); textArea=new JTextArea(10,15); textArea.setText

7、Press any key on the keyboard.“); textArea.setEnabled(false); addKeyListener(this); getContentPane().add(textArea); setSize(350,100); show(); public void keyPressed(KeyEvent e) line1=“Key pressed:“+e.getKeyText(e.getKeyCode(); setLines2and3(e); public void keyReleased(KeyEvent e) linel=“Key releas

8、ed:“+e.getKeyText(e.getKeyCode(); setLines2and3(e); public void keyTyped(KeyEvent e) ULine1=“Key typed:“+e.getKeychar()/U; setLines2and3(e); private void setLines2and3(KeyEvent e) line2=“This key is“+(e.isActionKey()?“:“not“)+“an action key“; String temp=e.getKeyModifiersText(e.getModifiers(); line3

9、Modifier keys pressed:“+(temp.equals(“)?“none“:temp); textArea.setText(line1+“n“+line2+“/n“+line3+“n“); public static void main(String args) java3 app=new java3(); UaddWindowListener(new Windowadapterl()/U public void windowClosing(WindowEvent e) System.exit(0); ); (分数:30.00)_计算机二级 JAVA-32答案解析(总分:

10、100.00,做题时间:90 分钟)一、B1基本操作题/B(总题数: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处:new int20 第 2处:i=0;i20 第 3处

11、i%2! =0)解析:解析 第 1处定义了长度为 20的一维整型数组 a;第 2处的 for循环将数组元素的下标值赋给数组元素;第 3处判断数组各个元素下标是否为奇数。二、B2简单应用题/B(总题数:1,分数:40.00)2.本题中,窗口的背景色为系统桌面的颜色,在窗口中分别画空心和实心的黑色矩形、深灰色圆角矩形和浅灰色椭圆形,并且画白色粗体的“欢迎学习 Java!”字符串。 import java.awt.*; import javax.swing.*; public class java2 public static void main(Stringargs) FillFrame fra

12、me=new FillFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); class FillFrame extends JFrame public FillFrame() setTitle(“java2“); setSize(WIDTH,HEIGHT); FillPanel panel=new FillPanel(); panel.setBackround(SystemColor.desktop); Container contentPane=getContentPane(); conten

13、tPane.add(panel); public static final int WIDTH=400; public static final int HEIGHT=250; class FillPanel extends JPanel public void paintComponent(Graphics g) _; g.setColor(new Color(10,10,10); g.drawRect(10,10,100,30); g.setColor(new Color(100,100,100); g.drawRoundRect(150,10,100,30,15,15); g.setCo

14、lor(new Color(150,150,150); g.drawOval(280,10,80,30); g.setColor(new Color(10,10,10); g.fillRect(10,110,100,30); g.setColor(new Color(100,100,100); g.fillRoundRect(150,110,100,30,15,15); g.setColor(new Color(150,150,150); g.fillOval(280,110,80,30); g.setColor(Color.white); Font f=new Font(“宋体“,_,20)

15、 g.setFont(f); g.drawstring(“欢迎学习 Java!“,150,200); (分数:40.00)_正确答案:(第 1处:super.paintComponent(g) 第 2处:Font.Bold)解析:解析 第 1处使用父类方法应使用 super来引用;第 2处为设置粗体。三、B3综合应用题/B(总题数:1,分数:30.00)3.本题的功能是监听键盘键的敲击,并显示在窗口中。 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class java3 Uextends J

16、Frame extends KeyListener/U private String linel=“,line2=“; private String line3=“; private JTextArea textArea; public java3() super(“java3“); textArea=new JTextArea(10,15); textArea.setText(“Press any key on the keyboard.“); textArea.setEnabled(false); addKeyListener(this); getContentPane().add(tex

17、tArea); setSize(350,100); show(); public void keyPressed(KeyEvent e) line1=“Key pressed:“+e.getKeyText(e.getKeyCode(); setLines2and3(e); public void keyReleased(KeyEvent e) linel=“Key released:“+e.getKeyText(e.getKeyCode(); setLines2and3(e); public void keyTyped(KeyEvent e) ULine1=“Key typed:“+e.get

18、Keychar()/U; setLines2and3(e); private void setLines2and3(KeyEvent e) line2=“This key is“+(e.isActionKey()?“:“not“)+“an action key“; String temp=e.getKeyModifiersText(e.getModifiers(); line3=“Modifier keys pressed:“+(temp.equals(“)?“none“:temp); textArea.setText(line1+“n“+line2+“/n“+line3+“n“); publ

19、ic static void main(String args) java3 app=new java3(); UaddWindowListener(new Windowadapterl()/U public void windowClosing(WindowEvent e) System.exit(0); ); (分数:30.00)_正确答案:(第 1处:extends JFrame implements KeyListener 第 2处:line1=“Key typed:“+e.getKeyChar() 第 3处:app.addWindowListener(new WindowAdapter()解析:解析 第 1处实现接口应用 implements;第 2处 Java是大小写敏感的,获得键盘值应使用getKeyChar()方法;第 3处窗体级监听器应注册给接收类。

展开阅读全文
相关资源
猜你喜欢
  • NC 12-04-24-1986 Standards System for Protection Against Corrosión Paint and Varnlsh Coatings Deíermination of Acid and Alkaline Solutions Resistance《防腐蚀保护的标准系统 油漆和清漆涂层 抗酸和碱金属溶液测定》.pdf NC 12-04-24-1986 Standards System for Protection Against Corrosión Paint and Varnlsh Coatings Deíermination of Acid and Alkaline Solutions Resistance《防腐蚀保护的标准系统 油漆和清漆涂层 抗酸和碱金属溶液测定》.pdf
  • NC 12-04-25-1986 corrosion Protection Standards Systum Metallic and Non-Metaliic Inorganic Coatings Brightness Determination《防腐蚀保护的标准系统 金属和非金属无机涂层 亮度测试》.pdf NC 12-04-25-1986 corrosion Protection Standards Systum Metallic and Non-Metaliic Inorganic Coatings Brightness Determination《防腐蚀保护的标准系统 金属和非金属无机涂层 亮度测试》.pdf
  • NC 12-04-26-1989 Standards System for Protection Against Corrosion Metallic and Non-Metallic Coatings General Requirements of Non-destructive Methods for Thickness Measurement《抗蚀保护.pdf NC 12-04-26-1989 Standards System for Protection Against Corrosion Metallic and Non-Metallic Coatings General Requirements of Non-destructive Methods for Thickness Measurement《抗蚀保护.pdf
  • NC 12-04-29-1988 Standards System for Protoction Against Corrosion Electrolytic Metallie Coatings Method- of Decermination of Internal Stress《抗蚀保护标准系统 电解金属外衣 内应力测量方法》.pdf NC 12-04-29-1988 Standards System for Protoction Against Corrosion Electrolytic Metallie Coatings Method- of Decermination of Internal Stress《抗蚀保护标准系统 电解金属外衣 内应力测量方法》.pdf
  • NC 12-04-30-1983 Standars System for Protection against Corrosion Electrotechnic Articles Accelerated C limatic Testing General Requirements《抗蚀保护标准系统 电解物质 加速 C 限制测试 一般要求》.pdf NC 12-04-30-1983 Standars System for Protection against Corrosion Electrotechnic Articles Accelerated C limatic Testing General Requirements《抗蚀保护标准系统 电解物质 加速 C 限制测试 一般要求》.pdf
  • NC 12-04-39-1987 Standards System for Protection Against Corrosion Acid Corrosion Inhibitors Methods for the Détermination of Protecting Capacity during Metal Acid Pickling《抗蚀保护标准系.pdf NC 12-04-39-1987 Standards System for Protection Against Corrosion Acid Corrosion Inhibitors Methods for the Détermination of Protecting Capacity during Metal Acid Pickling《抗蚀保护标准系.pdf
  • NC 12-04-40-1987 Standards System for Protecticn Against Corrosión Electrotschnical Devices Accelerared Test for Cold《抗蚀保护标准系统 电解装置 变冷加速测试》.pdf NC 12-04-40-1987 Standards System for Protecticn Against Corrosión Electrotschnical Devices Accelerared Test for Cold《抗蚀保护标准系统 电解装置 变冷加速测试》.pdf
  • NC 12-04-41-1987 Standaras System for Protection Against Corrosion Electrotechnical Devices Accelerated Test for Dry Heat《抗蚀保护标准系统 电解装置 干燥加速测试》.pdf NC 12-04-41-1987 Standaras System for Protection Against Corrosion Electrotechnical Devices Accelerated Test for Dry Heat《抗蚀保护标准系统 电解装置 干燥加速测试》.pdf
  • NC 12-04-42-1987 Standards Syetem for Protection Against Corrosion Electrotechnical Devices Accelerated Test for Cyclic Humid Heat《防腐蚀保护的标准系统 电技术装置 循环湿度热量加速测试》.pdf NC 12-04-42-1987 Standards Syetem for Protection Against Corrosion Electrotechnical Devices Accelerated Test for Cyclic Humid Heat《防腐蚀保护的标准系统 电技术装置 循环湿度热量加速测试》.pdf
  • 相关搜索

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

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