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

📄 bouncer.java

📁 书籍"Java_面向事件编程"的附带光盘代码
💻 JAVA
字号:
import objectdraw.*;import java.awt.Color;// moves each ball in the array up and downpublic class Bouncer extends ActiveObject {        // how many balls to bounce    private static final int BOUNCES = 20;        // speed and acceleration of ball motion    private static final double INITSPEED = -3;    private static final double GRAVITY = .125;        // length of pauses between moving a ball    private static final int STEPDELAY = 30;        // length of pause between picking balls to bounce    private static final int BOUNCEDELAY = 250;        // the set of balls to choose from    BallCollectionInterface allTheBalls;        public Bouncer( BallCollectionInterface theBalls ) {        allTheBalls = theBalls;        start();    }            public void run() {                // bounce BOUNCES randomly picked balls.        for ( int count = 0; count < BOUNCES; count ++ )            {                BBall ball = allTheBalls.pickRandomly();                                // animate the bounce                for ( double velocity = INITSPEED;                      velocity <= -INITSPEED;                      velocity = velocity + GRAVITY) {                    ball.move(0,velocity);                    pause( STEPDELAY);                }                                pause( BOUNCEDELAY);                            }    }    }

⌨️ 快捷键说明

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