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

📄 colorfulballmover.java~

📁 书籍"Java_面向事件编程"的附带光盘代码
💻 JAVA~
字号:
import objectdraw.*;import java.awt.*;import java.applet.*;// Animator for a BallListpublic 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();    }        private void moveOneBall(FilledOval ball) {        double pixelsMoved = 0;        while (pixelsMoved < distanceToMove) {            ball.move(SPEED, 0);            pause(PAUSETIME);            pixelsMoved = pixelsMoved + SPEED;        }    }        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 + -