




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一、 单项选择题1.下列不在applet生命周期中的方法是(C)。 A)init B)start C)execute D)stop2.KeyListener接口中处理键盘事件的处理器不包括(D)。 A)keyPressed B keyReleasd C keyTyped D mouseEntered3.第一次装载或重装applet时,都要调用(A)方法。 A)init B)start C)stop D)destroy4.鼠标进入组件时调用的方法是(B)。 )mouseExit B)mouseEntered C)mouseMoved D)mouseReleased5.按下按钮移动鼠标时调用(C)鼠标处理器 A)mouseMoued B)mouseReleased C)mouseDragged D)mouseClicked6.下列哪个事件不是所有GUI组件都能产生的事件 ( A )A)ActionEvent B)MouseEvent C)KeyEvent D)FocusEvent7.下列哪些事件处理方法不是定义在MouseListener中( D )A)mouseEntered B)mousePressed C)mouseClicked D)mouseMoved8. 下列哪些事件处理方法不是定义在KeyListener中( A )A)keyClicked B)keyPressed C)keyReleased D)keyPressed9在Applet应用程序的生命周期中,以下说法正确的是: (C)A)当打开浏览器窗口时,系统会自动调用start方法,在Applet应用程序的生命周期中,start方法可执行多次;B)当激活浏览器窗口时,系统会自动调用start方法,在Applet应用程序的生命周期中,start方法只可执行一次; C)当打开浏览器窗口时,系统会自动调用init方法,在Applet应用程序的生命周期中,init方法只可执行一次; D)当激活浏览器窗口时,系统会自动调用init方法,在Applet应用程序的生命周期中,init方法可执行多次。10.如果重写了Applet的paint方法,在以下何种情况中,会自动调用paint方法绘图。 (D)A)当浏览器运行时 B)当Applet 内容被覆盖后又重新显示时 C)在执行repaint方法重新绘图时 D)包括以上三种情况 11.在浏览器中执行applet 程序,以下选项中的哪个方法将被最后执行( C )。A)init()B)start() C)destroy() D)stop()12.在编写Java Applet程序时,需要在程序的开头写上( B )语句。A)import java.awt.* ; B)import java.applet.* ;C)import java.io.* ; D)import java.awt.event.* ;二、 填空题1. 使用MouseListener接口监听鼠标按下、松开、进入、退出和点击等行为。2. 使用MouseMotionListener接口监听鼠标的移动和拖动等行为。3. 默认情况下,JApplet的内容窗格使用BorderLayout布局管理器4.在applet程序的生命周期中,浏览器通过调用_init_、_start_、_stop_和destroy_方法来控制applet程序。5.Applet的_init_方法在开始时只执行一次,_start_方法在用户每次访问包含Applet的HTML文件时都被调用,_paint_方法可以用来在其中画图, _stop_方法在用户离开Applet所在的HTML页面时被调用。6.applet小程序需要继承_Applet/JApplet_类7.在显示或者重新显示applet小程序时,会调用_paint_方法8.JApplet内容窗格的缺省布局管理器是_BorderLayout_9.在网页中嵌入applet小程序的标记是_ _10.鼠标事件的监听接口是_MouseListener_和_MouseMotionListener_,键盘事件的监听接口是_KeyListener_。三、 判断题1. TextField和TextArea是用来接受用户输入的组件,但是也可以由程序控制使用户不能在其中输入信息。2. 用hide()或setVisible(false)方法可以使组件隐藏不可见,但是一旦隐藏便不能恢复显示。3. 一个Button对象,可以调用方法getLabel()获取其上的标签,从而判断是哪个按钮;Label也使用相同的方法。4. 所有的鼠标事件都由MouseEvent类的对象表示。5. 所有的鼠标事件都由实现了MouseListener监听接口的监听者来处理。6. 使用BorderLayout的容器最多只能放置5个组件,如果要放置更多的组件,则需要使用多层容器。7.使用GridLayout布局策略的容器中,所有的组件都有相同大小。8.一般情况下,applet都可以转化成application。9.在applet生存周期中stop方法总是在destroy方法之后执行。答案:1. 对2. 错,可以恢复3. 后半句错4. 对5. 错,鼠标移动和拖动事件由实现了MouseMotionListener监听接口的监听者来处理6. 对7. 对8. 对9. 错四、 编程题1请编写一个Applet,其功能为:用它的HTML文件中给出的两个整型参数做加数,求它们的和并显示结果。(知识点考察:Applet生命周期,编写Applet文件的方法)import java.awt.*;import java.applet.*;public class Applet1 extends AppletLabel a;public void init()int x= Integer.parseInt(getParameter(x); int y= Integer.parseInt(getParameter(y);int z=x+y; a=new Label(HTML给出的两个参数 +x+, +y+之和为 +z);add(a);HTML 文件2请编写一个Applet,用它的HTML文件中给出的两个float型参数作加数,求它们的和,并显示结果。(知识点考察:Applet生命周期,编写Applet文件的方法)import java.awt.*;import java.applet.*;public class Applet1 extends AppletLabel a;public void init() float x= Float.valueOf(getParameter(x).floatValue(); float y= Float.valueOf(getParameter(y).floatValue(); float z= x+y; a=new Label(HTML给出的两个参数 +x+ , +y+ 和为 +z); add(a);HTML 文件略。3请编写一个实现如下功能的Applet:从它的HTML文件中取三个参数 x, y, op 做算术运算,其中 x, y为 int 型数据,op 为运算符(、 之一),请显示 x op y 的结果。(知识点考察:从HTML文件中获取参数的方法)import java.awt.*; import java.applet.*;public class Applet1 extends Appletint x, y;char op; public void paint(Graphics g)String str= ;x=Integer.parseInt(getParameter(x);y=Integer.parseInt(getParameter(y);op=getParameter(op).charAt(0);switch (op)case + : str=str+x+ + +y+ = +(x+y); break;case - : str=str+x+ - +y+ = +(x-y); break;case * : str=str+x+ * +y+ = +(x*y); break;case / : str=str+x+ / +y+ = +(x/y); break; default : g.drawString(不能识别的运算符 +op,20,60); System.exit(0);g.drawString(str,20,100);HTML 文件略。4编写小程序,小程序界面设置BorderLayout布局,创建一个面板JPanel,面板放置一个文本框、两个按钮,把面板放置在小程序的中间。(知识点考察:BorderLayout布局管理器的使用方法,在面板中放置组件)import java.awt.*;import javax.swing.*;public class MyApplet extends JAppletJButton b1,b2;JTextField tf;JPanel p1;/面板-用来放组件:按钮、标签、文本框、。public void init()p1=new JPanel();/创建面板b1=new JButton(按钮1);b2=new JButton(按钮2);tf=new JTextField(20);p1.add(b1);p1.add(b2);p1.add(tf);this.getContentPane().add(p1,BorderLayout.CENTER);5. 编写Applet, 其中包含两个按钮,它们的标签分别为“画正方形”和“画圆”,点击按钮“画正方形”时,通过paint()方法以坐标(10,10)为左上角画一个边长为60的兰色正方形框;点击按钮“画圆”时,画一个半径为50的红色填充圆,该圆内切于左上角坐标为(100,100)的正方形。如果那个按钮被点击,就使该按钮变得不可见。(知识点考察:在Applet中绘制图形,填充颜色,按钮的事件触发)程序import java.awt.*;import java .awt .event .*;import java.applet.*;public class Applet1 extends Applet implements ActionListener int i; Button btn1, btn2;public void init()btn1=new Button(画正方形);btn2=new Button(画圆);add(btn1);add(btn2);btn1.addActionListener(this);btn2.addActionListener(this);public void paint(Graphics g)if(i=1)g.setColor(Color. blue);g.drawRect(10,10,60,60); btn1.setVisible(false); if(i=2)g.setColor(Color. red);g.fillOval(100,100,100,100); btn2.setVisible(false); public void actionPerformed(ActionEvent e)if(e.getSource()=btn1)i=1; if(e.getSource()=btn2)i=2; repaint();6. 编写Applet, 其中包含两个按钮:按钮上的标签分别为“确定”和“取消”。当点击“确定” 按钮时,通过paint()方法在坐标(20,80)处,用绿色显示点击“确定”按钮的次数;当点击“取消” 按钮时,通过paint()方法在坐标(20,100)处,用红色显示点击“取消”按钮的次数(要求“确定”和“取消”的次数同时显示在Applet中)。 (知识点考察:按钮触发方法,paint方法的使用)程序import java.awt.*;import java .awt .event .*;import java.applet.*;public class Applet1 extends Applet implements ActionListener int j=0,k=0; Button btn1, btn2;public void init()btn1=new Button(确定); btn2=new Button(取消);add(btn1);add(btn2);btn1.addActionListener(this);btn2.addActionListener(this);public void paint(Graphics g)g.setColor(Color.green);g.drawString(你点击了确定按钮 +j+ 次,20,80);g.setColor(Color.red);g.drawString(你点击了取消按钮 +k+ 次,20,100); public void actionPerformed(ActionEvent e)if(e.getSource()=btn1) j+; if(e.getSource()=btn2) k+; repaint( ); 7. 编写Applet, 当鼠标进入Applet时,通过paint()方法以(60,60)为左上角坐标,填充一个颜色为黄色的、边长为60的正方形;鼠标移出时,以(60,120)为左上角坐标,画一个颜色为绿色的、边长为30的正方形框。(知识点考察:mouseEntered和mouseMoved方法的使用,应用paint方法绘制正方形)程序import java.awt.*;import java.applet.*;import java.awt.event.*;public class Applet1 extends Applet implements MouseListenerint i;public void init()addMouseListener(this); public void paint(Graphics g)if(i=1) g.setColor(Color. yellow); g.fillRect(60,60,60,60); if(i=2) g.setColor(Color.green); g.drawRect(60,120,30,30); public void mouseClicked(MouseEvent e)public void mousePressed(MouseEvent e)public void mouseEntered(MouseEvent e)i=1;repaint(); public void mouseExited(MouseEvent e) i=2;repaint(); public void mouseReleased(MouseEvent e)8. 编写Applet, 当鼠标进入Applet时,通过paint()方法在坐标(20,50)处,显示一幅图像,图像名称为a.gif,显示的高、宽分别为50、80;鼠标移出时,在坐标(70,130)处,显示另一幅图像,图像名称为b.gif,显示的高、宽分别为80、60。这些图像与嵌入该小程序的网页在同一目录下(程序中用到的图像在计算机中找)。(知识点考察:mouseEntered和mouseMoved方法的使用,应用paint方法在指定位置绘制图像)程序import java.awt.*;import java.applet.*;import java.awt.event.*;public class Applet1 extends Applet implements MouseListenerint i;Image pic1,pic2;public void init()pic1=getImage(getDocumentBase(),a.gif);pic2=getImage(getDocumentBase(),b.gif);addMouseListener(this);public void paint(Graphics g)if(i=1)g.drawImage(pic1,20,50,50,80,this);if(i=2)g.drawImage(pic2,70,130,80,60,this);public void mouseClicked(MouseEvent e)public void mousePressed(MouseEvent e)public void mouseEntered(MouseEvent e)i=1;repaint();public void mouseExited(MouseEvent e)i=2;repaint();public void mouseReleased(MouseEvent e)9. 编写Applet, 通过paint()方法在鼠标压下时,在坐标(30,30)处显示一幅图像,图像名称为a.gif,显示的高、宽分别为90、90(程序中用到的图像在计算机中找,并使其与嵌入该小程序的网页在同一目录)。点击鼠标时,在窗口的状态栏中输出字符串“这个图像真美丽!”。(知识点考察:mousePressed和mouseClicked方法的使用,应用paint方法在指定坐标点绘制图像)程序import java.awt.*;import java.applet.*;import java.awt.event.*;public class Applet1 extends Applet implements MouseListenerint i;Image pic;public void init()pic=getImage(getDocumentBase(),a.gif);addMouseListener(this);public void paint(Graphics g)if(i=1)g.drawImage(pic,30,30,90,90,this);if(i=2)showStatus(“这个图像真美丽!”);public void mouseClicked(MouseEvent e)i=2;repaint();public void mousePressed(MouseEvent e)i=1;repaint(); public void mouseEntered(MouseEvent e)public void mouseExited(MouseEvent e)public void mouseReleased(MouseEvent e)10. 编写Applet, 当压下鼠标时,在鼠标压下处显示字符串“释放鼠标将显示图象”,要求显示字体的名称为Courier、普通体、字体大小为25。当释放鼠标时,以鼠标释放处为左上角坐标,显示一幅jpg图像,图像显示的宽、高分别为200、120像素(图像在计算机中查找)。(知识点考察:mousePressed和mouseReleased方法的使用,应用paint方法绘制图像)程序import java.awt.*;import java.applet.*;import java.awt.event.*;public class Applet1 extends Applet implements MouseListenerint x,y,k;Image pic;public void init()pic=getImage(getDocumentBase(),a.jpg);addMouseListener(this);public void paint(Graphics g)if(k=1) Font f1=new Font(Courier,Font.PLAIN,25); g.setFont(f1); g.drawString(释放鼠标将显示图象。,x,y); if(k=2)g.drawImage(pic,x,y,200,160,this);public void mouseClicked(MouseEvent e)public void mousePressed(MouseEvent e)k=1;x=e.getX();y=e.getY();repaint(); public void mouseEntered(MouseEvent e) public void mouseExited(MouseEvent e) public void mouseReleased(MouseEvent e)k=2;x=e.getX();y=e.getY();repaint(); 11编写Applet, 当按下键盘键时,在Applet中通过paint()方法,在(25,20)位置处显示你按下的键的名称。(知识点考察:键盘事件处理过程,paint方法绘制字符串)程序import java.awt.*;import java .awt .event .*;import java.applet.*;public class Applet1 extends Applet implements KeyListener String name= ;public void init() addKeyListener(this);requestFocus(); public void paint(Graphics g) g.drawString (你按下的键是:+name,25,20);public void keyPressed(KeyEvent e)name=e.getKeyText (e.getKeyCode ();repaint();public void keyReleased(KeyEvent e)public void keyTyped(KeyEvent e)12编写小程序,响应键盘事件:敲击字母r,改变小程序背景色为red;敲击字母b,改变小程序背景色为blue;敲击字母g,改变小程序背景色为green;其他字母,改变小程序背景色为black。(知识点考察:键盘响应事件,改变背景色)/ Key.javaimport java.applet.Applet;import java.awt.*;import java.awt.event.*;public class Applet1 extends Applet implements KeyListenerchar ch; public void init() addKeyListener( this ); requestFocus();/获取焦点 public void paint( Graphics g ) if(ch=r|ch=R) this.setBackground(Color.red); public void keyPressed( KeyEvent e )/键压下时执行 public void keyReleased( KeyEvent e )/键释放时执行 public void keyTyped( KeyEvent e )/键敲击时执行 ch=e.getKeyChar(); repaint(); 13编写java小程序,在小程序界面画一个彩色球,当压下键盘上的4个方向键时,彩色球能向指定的方向移动。(知识点考察:响应键盘事件)import java.awt.*;import java.applet.*;import java.awt.event.*;public class Applet1 extends Appletchar ch;int x=20,y=20;public void init()this.addKeyListener(new KeyAdapter()public void keyPressed(KeyEvent e)if(e.getKeyCode()=e.VK_DOWN)y+=2;if(e.getKeyCode()=e.VK_UP)y-=2;if(e.getKeyCode()=e.VK_RIGHT)x+=2;if(e.getKeyCode()=e.VK_LEFT)x-=2;repaint(););this.requestFocus();public void paint(Graphics g)g.setColor(Color.blue);g.fillOval(x,y,30,30);14编写小程序,使用内部类响应鼠标点击事件:点击鼠标,以点击处为中心画圆。(知识点考察:mouseClicked方法的使用,用鼠标触发)import java.awt.*;import java.applet.*;import java.awt.event.*;/点击鼠标,以该点为中心画圆public class Applet1 extends Applet int x,y;public void init()addMouseListener(new MyMouse();public void paint(Graphics g)g.setColor(Color.red);g.fillOval(x-50,y-50,100,100);/定义内部类,处理鼠标点击/鼠标适配器类MouseAdapter:已实现鼠标接口中的所有抽象方法,但只定义了一个空方法体。class MyMouse extends MouseAdapter /覆盖父类的鼠标点击方法。public void mouseClicked(MouseEvent e)x=e.getX();y=e.getY();repaint();15. 请编写一个Applet,功能为:在其窗口中使用FlowLayout布局管理器,按右对齐方式安排两个按钮,令它们的标签分别为”画矩形”、”画椭圆”,如果某个按钮框被点击了,就实现该按钮指定的功能。(知识点考察:按钮事件处理过程,绘制图形)程序import java.awt.*;import java.applet.*;import java.awt.event.*;public class Applet1 extends Applet implements ActionListenerButton b1,b2; int i;public void init() setLayout(new FlowLayout(FlowLayout.RIGHT);b1=new Button(画矩形); add(b1);b1.addActionListener(this); b2=new Button(画椭圆); add(b2);b2.addActionListener(this); public void paint(Graphics g)if(i=1) g.drawRect(50,50,60,30);if(i=2) g.drawOval(50,50,60,30); public void actionPerformed(ActionEvent e)if(e.getSource()=b1) i=1; if(e.getSource()=b2) i=2;repaint();16请编写一个Applet,功能为:在其窗口中先使用FlowLa
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 咨询服务费收取方案范本
- 考研报考咨询宣传方案
- 2025版司法局《调查取证申请书》(空白模板)
- 线上读书活动策划方案公司
- 加油站营销送礼品方案
- 福鼎小型连续墙施工方案
- 围堤清障除杂施工方案
- 建筑转行展览活动方案设计
- 建筑模板废料清除方案设计
- 认知三板斧营销方案
- 内蒙古呼伦贝尔农垦集团有限公司招聘笔试题库及答案详解(历年真题)
- 2025年省农垦集团有限公司人员招聘笔试备考附答案详解(完整版)
- 基于核心素养的幼儿园教学评价体系
- 2025至2030中国X光安检机行业项目调研及市场前景预测评估报告
- 2025年市中区畜牧兽医、动物检疫站事业单位招聘考试真题库及答案
- 幼儿园小班数学活动《认识1和许多》课件
- 直播运营基本知识培训课件
- 小学主题班会《立规矩改》课件
- 2025年遂宁社区专职工作人员招聘考试笔试试题含答案
- 新闻采编业务知识培训课件
- 孕期阴道炎课件
评论
0/150
提交评论