📄 colorfulballmover.java
字号:
import objectdraw.*;import java.awt.*;import java.applet.*;// Animator for a BallList, changes colors while movingpublic class ColorfulBallMover extends ActiveObject { private static final int PAUSETIME = 20; private static final double SPEED = 1; private AudioClip noise; // the list of balls to animate private BallListInterface ballList; // distance that each ball should move private int distanceToMove; public ColorfulBallMover(BallListInterface aList, int distance, AudioClip theNoise) { ballList = aList; distanceToMove = distance; noise = theNoise; start(); } // move the specified ball private void moveOneBall(FilledOval ball) { double pixelsMoved = 0; while (pixelsMoved < distanceToMove) { ball.move(SPEED, 0); pause(PAUSETIME); pixelsMoved = pixelsMoved + SPEED; } } // traverse the list, move each ball once, and change its color public void run() { RandomIntGenerator gen = new RandomIntGenerator(0, 255); while (!ballList.isEmpty()) { FilledOval nextBall = ballList.getFirst(); Color c = new Color(gen.nextValue(), gen.nextValue(), gen.nextValue()); nextBall.setColor(c); noise.play(); moveOneBall(nextBall); ballList = ballList.getRest(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -