⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bouncingball.java~

📁 书籍"Java_面向事件编程"的附带光盘代码
💻 JAVA~
字号:
import objectdraw.*;// animate the motion of a simple, falling ballpublic class BouncingBall extends ActiveObject{    // size and speed of balls    private static final double BALLSIZE = 30;    private static final double DELAY_TIME = 33;    private double ySpeed = 0.1;        // y coordinate where ball disappears    private double bottom;        // the ball    private FilledOval ball;        // the paddle    private FilledRect paddle;        public BouncingBall(double x, double y, FilledRect thePaddle, DrawingCanvas aCanvas)    {                ball = new FilledOval(x - BALLSIZE/2 , y,                              BALLSIZE, BALLSIZE, aCanvas);        bottom = aCanvas.getHeight();        paddle = thePaddle;    }        public void run()    {        double top = ball.getY();                // move the ball repeatedly until it fall off screen        while (ball.getY() < bottom ) {                 // determine how much time has passed            currentTime = System.currentTimeMillis();            elapsedTime = currentTime - lastTime;            // restart timing            lastTime = currentTime;            ball.move(0, ySpeed * elapsedTime);                        if (ball.overlaps(paddle) || ball.getY() < top){                ySpeed = -ySpeed;            }            pause(DELAY_TIME);        }                ball.removeFromCanvas();    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -