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

📄 ballmover.java

📁 书籍"Java_面向事件编程"的附带光盘代码
💻 JAVA
字号:
import objectdraw.*;// Animator for a BallListpublic class BallMover extends ActiveObject {        private static final int PAUSETIME = 20;    private static final double SPEED = 1;        // the list of balls to animate    private BallListInterface ballList;        // distance that each ball should move    private int distanceToMove;        public BallMover(BallListInterface aList, int distance) {        ballList = aList;        distanceToMove = distance;                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 and move each ball once    public void run() {        while (!ballList.isEmpty()) {            FilledOval ball = ballList.getFirst();            moveOneBall(ball);            ballList = ballList.getRest();        }    }}

⌨️ 快捷键说明

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