📄 bouncer.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 + -