ImageVerifierCode 换一换
格式:DOC , 页数:8 ,大小:35.50KB ,
资源ID:1317783      下载积分:5000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-1317783.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(【计算机类职业资格】(A)二级JAVA笔试-3及答案解析.doc)为本站会员(花仙子)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

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

1、A)二级 JAVA 笔试-3 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.本题的功能是获得字符串“China”的长度和最后一个字符,并将这些信息打印出来。public class java1public static void rnain(String args)_;str=“China“;int n=0;_;char c;_;System. out. println(“字符串中共有“+n+“个字符。最后一个字符是:“+c);(分数:30.00)填空项 1:_二、简单应用题(总题数:1,分数:30.00)2.本题的功能是通过鼠标确定

2、两个点,然后画两点间的直线。窗口中有一个按钮“Draw line”,单击该按钮后,它就处于按下状态,然后用鼠标在窗口中单击一下,在单击的地方就会出现一个坐标圆点,用鼠标在另外一个地方单击一下又会出现另外一个圆点,并且此时在两个坐标圆点间画出一条直线,且“Draw line”处于可用状态,再单击这个按钮就可以画另外一条直线。import java. awt. * ;import java. awt. event. * ;import javax. swing. * ;class EventQueuePanel extends JPanel implements ActionListenerEve

3、ntQueuePanel()JButton button=new JButton(“Draw line“);add(button);button. addActionListener(this);public void actionPerformed(ActionEvent evt)( Graphics g=getGraphics();_p= getClick();g. drawOval(p. x-2, p. y-2, 4, 4);Point q=getClick();g. drawOval(q. x-2, q. y-2, 4, 4);g. drawLine(p, x, p. y, q. x,

4、 q. y);g. dispose()public Point getClick()EventQueue eq=Toolkit. getDefaultToolkit(). getSystemEventQueue();while (true)tryAWTEvent evt=eq. getNextEvent();if (evt. getlD()=MouseEvent. MOUSEPRESSED)MouseEvent mevt=(MouseEvent)evt;Point p =_();Point top=getRootPane(). getLocation();p. x-=top. x;p. y-=

5、top. y;return p;catch(InterruptedException e)private int y=60;class EventQueueFrame extends JFramepublic EventQueueFrame()setTitle(“java2“);setSize(300,200);addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System. exit(0););Container contentPane=getContentPane();contentPa

6、ne. add( new EventQueuePanel();public class java2public static void main(String args)Frame frame=new EventQueueFrame();frame. show();(分数:30.00)填空项 1:_三、综合应用题(总题数:1,分数:40.00)3.本题是一个 Applet,功能是用鼠标画不同颜色的图形。页面中有 5 个按钮“画红色图形”、“画绿色图形”、“画蓝色图形”、“橡皮”和“清除”,单击前三个按钮中的一个,按住鼠标左键或右键在面板中拖动,就能画出对应颜色的线条,单击“橡皮”按钮,按住鼠标

7、左键或右键在面板中拖动就能将面板中的图形擦除掉,单击“清除”按钮,就能将面板中所有的图形清除掉。import java. applet. * ;import java. awt. * ;import java. awt. event. * ;public class java3 extends Applet implements ActionListenerint x-1, y=-l, rubberNote=0, clearNote=0;Color c=new Color(255,0,0);int con=3;Button b_red, b_blue, b_green, b_clear, b_

8、quit ;public void init()addMouseMotionListener(this);b_red=new Button(“画红色图形“);b_blue=new Button(“画蓝色图形“);b_green=new Button(“画绿色图形“) ;b_quit=new Button(“橡皮“);bclear=new Button(“清除“);add(b_red);add(b_green);add(b_blue);add(b_quit);add(b_clear);b_red. addActionListener(this);b_green. addActionListene

9、r(this);b_blue. addActionListener(this);b_quit. addActionListener(this);b_clear. addActionListener(this);public void paint()if(x!=-1g. fillOval(x, y, con, con);else if(rubberNote=1else if(clearNote=1public void mouseDragged(MouseEvent e)x=(int) e. getX(); y=(int) e. getY(); repaint();public void mou

10、seMoved(MouseEvent e)public void update(Graphics g)paint(g);public void actionPerformed(Event e)if(e. getSource()=b_red)rubberNote=0; clearNote=0; c=new Color(255,0,0);else if(e. getSource()=b green)rubberNote=0; clearNote=0; c=new Color(0,255,0);else if(e. getSource()=b_blue)rubberNote=0; clearNote

11、0; c=new Color(0,0,255);if(e. getSource()=b_quit)rubberNote=1; clearNote=0;if(e. getSource()=b_clear)clearNote=1; rubberNote=0; repaint();(分数:40.00)填空项 1:_(A)二级 JAVA 笔试-3 答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.本题的功能是获得字符串“China”的长度和最后一个字符,并将这些信息打印出来。public class java1public static void

12、rnain(String args)_;str=“China“;int n=0;_;char c;_;System. out. println(“字符串中共有“+n+“个字符。最后一个字符是:“+c);(分数:30.00)填空项 1:_ (正确答案:第 1 处:String str第 2 处:n=str. length()第 3 处:c=str. charAt(n-1))解析:解析 第 1 处定义一个 String 字符串类型的变量 str;第 2 处将 str 字符串的长度赋给 n;第 3处用 str 的 charAt 方法获得最后一个字符并赋给 C,用 n-1 来定位最后一个字符。二、简单

13、应用题(总题数:1,分数:30.00)2.本题的功能是通过鼠标确定两个点,然后画两点间的直线。窗口中有一个按钮“Draw line”,单击该按钮后,它就处于按下状态,然后用鼠标在窗口中单击一下,在单击的地方就会出现一个坐标圆点,用鼠标在另外一个地方单击一下又会出现另外一个圆点,并且此时在两个坐标圆点间画出一条直线,且“Draw line”处于可用状态,再单击这个按钮就可以画另外一条直线。import java. awt. * ;import java. awt. event. * ;import javax. swing. * ;class EventQueuePanel extends JP

14、anel implements ActionListenerEventQueuePanel()JButton button=new JButton(“Draw line“);add(button);button. addActionListener(this);public void actionPerformed(ActionEvent evt)( Graphics g=getGraphics();_p= getClick();g. drawOval(p. x-2, p. y-2, 4, 4);Point q=getClick();g. drawOval(q. x-2, q. y-2, 4,

15、 4);g. drawLine(p, x, p. y, q. x, q. y);g. dispose()public Point getClick()EventQueue eq=Toolkit. getDefaultToolkit(). getSystemEventQueue();while (true)tryAWTEvent evt=eq. getNextEvent();if (evt. getlD()=MouseEvent. MOUSEPRESSED)MouseEvent mevt=(MouseEvent)evt;Point p =_();Point top=getRootPane().

16、getLocation();p. x-=top. x;p. y-=top. y;return p;catch(InterruptedException e)private int y=60;class EventQueueFrame extends JFramepublic EventQueueFrame()setTitle(“java2“);setSize(300,200);addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System. exit(0););Container conte

17、ntPane=getContentPane();contentPane. add( new EventQueuePanel();public class java2public static void main(String args)Frame frame=new EventQueueFrame();frame. show();(分数:30.00)填空项 1:_ (正确答案:第 1 处:Point第 2 处:nevt. getPoint)解析:解析 第 1 处表示获得 Point 型的坐标给了 P;第 2 处获得鼠标单击的坐标。三、综合应用题(总题数:1,分数:40.00)3.本题是一个 A

18、pplet,功能是用鼠标画不同颜色的图形。页面中有 5 个按钮“画红色图形”、“画绿色图形”、“画蓝色图形”、“橡皮”和“清除”,单击前三个按钮中的一个,按住鼠标左键或右键在面板中拖动,就能画出对应颜色的线条,单击“橡皮”按钮,按住鼠标左键或右键在面板中拖动就能将面板中的图形擦除掉,单击“清除”按钮,就能将面板中所有的图形清除掉。import java. applet. * ;import java. awt. * ;import java. awt. event. * ;public class java3 extends Applet implements ActionListenerin

19、t x-1, y=-l, rubberNote=0, clearNote=0;Color c=new Color(255,0,0);int con=3;Button b_red, b_blue, b_green, b_clear, b_quit ;public void init()addMouseMotionListener(this);b_red=new Button(“画红色图形“);b_blue=new Button(“画蓝色图形“);b_green=new Button(“画绿色图形“) ;b_quit=new Button(“橡皮“);bclear=new Button(“清除“)

20、add(b_red);add(b_green);add(b_blue);add(b_quit);add(b_clear);b_red. addActionListener(this);b_green. addActionListener(this);b_blue. addActionListener(this);b_quit. addActionListener(this);b_clear. addActionListener(this);public void paint()if(x!=-1g. fillOval(x, y, con, con);else if(rubberNote=1el

21、se if(clearNote=1public void mouseDragged(MouseEvent e)x=(int) e. getX(); y=(int) e. getY(); repaint();public void mouseMoved(MouseEvent e)public void update(Graphics g)paint(g);public void actionPerformed(Event e)if(e. getSource()=b_red)rubberNote=0; clearNote=0; c=new Color(255,0,0);else if(e. get

22、Source()=b green)rubberNote=0; clearNote=0; c=new Color(0,255,0);else if(e. getSource()=b_blue)rubberNote=0; clearNote=0; c=new Color(0,0,255);if(e. getSource()=b_quit)rubberNote=1; clearNote=0;if(e. getSource()=b_clear)clearNote=1; rubberNote=0; repaint();(分数:40.00)填空项 1:_ (正确答案:第 1 处:extends Applet implements ActionListener, MouseMotionListener第 2 处:public void paint(Graphics g)第 3 处:public void actionPerformed(ActionEvent e))解析:解析 第 1 处继承 Applet 实现构件动作监听接口和鼠标移动监听接口;第 2 处定义 paint 绘制图形方法以 Graphics 类对象作为参数;第 3 处 actionPerformed 方法是发生对象的操作事件时调用,以一个监听动作类的对象 e 为参数。

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