阅读以下说明和JAVA 2代码,填入(n)处。[说明]以下程序实现了利用鼠标任意移动圆形的位置,仔细阅读代码和相关注释,将程序补充完整。[代码6-1]import java.awt.*;import java.awt.event.*;public class CIUSAMPLE extends Frame. implements MouseMotionListener, MouseListener{static CIUSAMPLE frm=new CIUSAMPLE ( );int x=70,y=60,posX=70,posY=60,dx,dy;public static void main (String args[]){frm.setTitle ("Dragging a circle");frm.setSize (200,150);(1)ffm.addMouseMotionListener (frm);frm.setVisible (true);}public void mousePressed (MouseEvent e){(2)dy=e.getY ( ) -posY;}public void mouseDragged (MouseEvent e){(3)y=e.getY ( ) -dy;if(dx>0dx<50dy>0dy<50) //如果指针落在正方形区域内{Graphicsg=getGraphics ( );(4)}}public void paint (Graphics g){g.setColor (Color.pink); //设置绘图颜色为粉红g.fillOval(x,y,50,50); //以基准点为图形在左上角绘出圆形(5)posY=y;}public void mouseMoved (MouseEvent e) {}public void mouseReleased (MouseEvent e) {}public void mouseEntered (MouseEvent e) {}public void mouseExited (MouseEvent e) {}public void mouseClicked (MouseEvent e) {}}

阅读以下说明和JAVA 2代码,填入(n)处。

[说明]

以下程序实现了利用鼠标任意移动圆形的位置,仔细阅读代码和相关注释,将程序补充完整。

[代码6-1]

import java.awt.*;

import java.awt.event.*;

public class CIUSAMPLE extends Frame. implements MouseMotionListener, MouseListener

{

static CIUSAMPLE frm=new CIUSAMPLE ( );

int x=70,y=60,posX=70,posY=60,dx,dy;

public static void main (String args[])

{

frm.setTitle ("Dragging a circle");

frm.setSize (200,150);

(1)

ffm.addMouseMotionListener (frm);

frm.setVisible (true);

}

public void mousePressed (MouseEvent e)

{

(2)

dy=e.getY ( ) -posY;

}

public void mouseDragged (MouseEvent e)

{

(3)

y=e.getY ( ) -dy;

if(dx>0&&dx<50&&dy>0&&dy<50) //如果指针落在正方形区域内

{

Graphicsg=getGraphics ( );

(4)

}

}

public void paint (Graphics g)

{

g.setColor (Color.pink); //设置绘图颜色为粉红

g.fillOval(x,y,50,50); //以基准点为图形在左上角绘出圆形

(5)

posY=y;

}

public void mouseMoved (MouseEvent e) {}

public void mouseReleased (MouseEvent e) {}

public void mouseEntered (MouseEvent e) {}

public void mouseExited (MouseEvent e) {}

public void mouseClicked (MouseEvent e) {}

}


相关考题:

阅读以下说明和JAVA2代码,将应填入(n)处的字句写在对应栏内。【说明】以下程序实现了利用鼠标任意移动该圆形的位置,仔细阅读代码和相关注释,将程序补充完整。【代码6】import java.awt.*;import java.awt.event.*;public class CIUSAMPLE extends Frame. implements MouseMotionListener, MouseListener{static CIUSAMPLE frm=new CIUSAMPLE ();int x=70,y=60,posX=70,posY=60,dx,dy;public static void main ( String args[]){frm.setTitle ("Dragging a circle");frm.setSize ( 200,150 );(1)frm.addMouseMotionListener ( frm );frm. setVisible ( true );}public void mousePressed ( MouseEvent e ){(2)dy=e.getY () -posY;}public void mouseDragged ( MouseEvent e ){(3)y=e.getY () -dy;if ( dx>0 dx<50 dy>0 dy<50 ) //如果指我落在正方形区域内{Graphics g=getGraphics ();(4)}}public void paint ( Graphics g ){g.setColor ( Color. pink ); // 设置绘图颜色为粉红g.fillOval ( x,y,50,50 ); //以基准点为图形的左上角绘出圆形(5)posY=y;}public void mouseMoved ( MouseEvent e ) { }public void mouseReleased ( MouseEvent e ) { }public void mouseEntered ( MouseEvent e ) { }public void mouseExited ( MouseEvent e ) { }public void mouseClicked ( MouseEvent e ) { }}

阅读以下说明和C++代码,填入(n)处。[说明]以下C++代码使用虚函数实现了同一基类shape派生出来的Class rectangle、Class triangle、Class circle实现了计算矩形、圆形面积的计算。仔细阅读以下代码,将(n)处语句补充完整。[代码5-1]include<iostream.h>define PI 3.14159class shape {//基类protected:(1);public:(2);(3);};[代码5-2]class rectangle: public shape {public:rectangle (int x2,int y2,int r2): (4) {};double area ( ) {return x*y; };};class circle: public shape {public:circle (int x3,int y3,int r3):(5){};double area ( ) {return r*r*PI; };};[代码5-3]void main ( ){rectangle r (10,20,0);circle c (0,0,30);shape (6);cout<<"长方形面积="<<s1->area ( ) <<endl;cout<<"圆形面积="<<s2->area ( ) <<endl;}[运行结果]长方形面积=200圆形面积=2827.43

阅读以下说明和C++码,将相应的文字填入(n)处,写在对应栏内。[说明]以下代码实现了对象引用作为函数参数,仔细阅读以下代码,分析运行结果,填入(n)处。[代码]include<iostream.h>class Sample{int x,y;public:Sample() {x=y=0; }Sample (int i, int j ) {x=i; y=j; }void copy ( Sample s ).,void setxy ( int i, int j ) {x=i; y=j; }void print ( {cout<<"x="<<x<<end1 ; cout <<"y="<<y<<end1;};void Sample: copy ( Sample s ){X=S.X;y=s.y;}void func ( Sample s1, Sample s2 ){s1.setxy ( 10,20 );s2.setxy ( 30,40 );}void main ( ){Sample p ( 1,2 ) ,q;q.copy ( p );time ( p,q );p.print ( );q.print ( );}运行结果(1)(2)(3)(4)

阅读以下说明和Java代码,将解答写入对应栏内。【说明】下面的程序的功能是利用实现Runnable接口的方法来创建线程,并利用它来执行响应的一些操作。最后使得m的执行结果:100,如图3。注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。class ClassName (1) Runnable {int n;(2) {try{Thread. sleep (2000);n=100;}catch( (3) e) {}}public static void main(String[ ]args) {try{ClassName a = new ClassName( );(4)threadl. (5) ();threadl, join( );int m=a.n;System. out. println("m=" + m);}catch( (3) e){}}}

阅读以下说明和JAVA 2代码,填入(n)处的。[说明]以下JAVA程序实现了在接口interface iShape2D的定义和应用,仔细阅读代码和相关注释,将程序补充完整。[代码6-1]interface iShape2D //定义接口{(1)(2)}(3)//实现CRectangle类{int width, height;(4) CRectangle (int w,int h) {width=w;height=h;}public void area ( ){ //定义area( )的处理方式System. out.println ("area="+width*height);}}(5)//实现CCircle类{double radius;(6) CCircle (double r) {radius=r;}public void area ( ) { //定义area( )的处理方式System.out.println ("area="+pi*radius*radius);}}[代码6-2]public class app10_4{public static void main(String args[]){CRectangle rect=new CRectangle (5,10);rect.area ( ); //调用CRectangle类里的area ( ) methodCCircle cir=new CCircle (2.0);cir.area ( ); //调用CCircl类里的area ( ) method}}

阅读以下说明和JAVA 2代码,将应填入(n)处的字句写在对应栏内。[说明]以下程序实现了在applet里移动图形文件,仔细阅读代码和相关注释,将程序补充完整。[代码6-1]import j ava. awt. *;import j ava.awt.event.*;import java.applet. Applet;public class AppCIU extends Applet implements MouseMotionListener, MouseListener{Image IMG nClick=over(this) title=放大; // 声明 Image 类类型的变量 IMG nClick=over(this) title=放大int x=70,y=60,posX=70,posY=60,dx,dy;public void init ( ){IMG nClick=over(this) title=放大=getImage ( getCodeBase ( ) ,"mouse.gif" ); //载入影像addMouseListener ( this );addMouseMotionListener ( this );}public void mousePressed ( MouseEvent e ){dx=e.getX()-posX; //取得按下之点与基准点X方向的距离dy=e.getY()-posY; //取得按下之点与基准点Y方向的距离}public void mouseDragged ( MouseEvent e ){(1)(2)if ( dx>0 dx<120 dy>0 dy<60 ) //如果指针落在图形上方{Graphics g=getGraphics ( );(3)}}public void paint ( Graphics g ){(4)(5)(6)}public void mouseMoved ( MouseEvent e ) {};public void mouseReleased ( MouseEvent e ) {};public void mouseEntered ( MouseEvent e ) {};public void mouseExited ( MouseEvent e ) {};public void mouseClicked ( MouseEvent e ) {};}

阅读以下说明和JAVA 2代码,将应填入(n)处的字句写在对应栏内。[说明]以下程序为类类型的变量应用实例,通过异常处理检验了类CCircle的变量的合法性,即参数半径应为非负值。仔细阅读代码和相关注释,将程序补充完整。[JAVA代码]//定义自己的异常类class CCircleException extends Exception{}// 定义类 CCircleclass CCircle{private double radius;public void setRadius ( double r ) (1){if ( r<0 ) {(2)}else(3)}Public void show ( ) {System. out. println ( "area="+3.14*radius*radius );}}public class ciusample{public static void main ( String args[] ){CCircle cir=new CCircle( );(4) {cir. setRadius ( -2.0 )}(5){System. out. println ( e+" throwed" ) ;}cir. show( ) ;}}

阅读以下说明和Java程序,填补代码中的空缺(1)~(6),将解答填入答题纸的对应栏内。【说明】很多依托扑克牌进行的游戏都要先洗牌。下面的Java代码运行时先生成一副扑克牌,洗牌后再按顺序打印每张牌的点数和花色。【Java代码】

试题三(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。