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

📄 chainreaction.java

📁 书籍"Java_面向事件编程"的附带光盘代码
💻 JAVA
字号:
import objectdraw.*;import java.applet.*;import java.awt.*;// On a mouse press, the user can place balls on the canvas;// On exiting the window, a simulation of a "chain reaction" begins:// the most recently drawn ball hits into the second most recently drawn,// which hits into the next ball, and so on.  If the mouse exits from the// bottom of the window then a colorful chain reaction will occur.public class ChainReaction extends WindowController {        // x and y coordinates of the first ball drawn    private static final int BALL_X = 300;    private static final int BALL_Y = 100;        // ball diameter    private static final int SIZE = 10;        // distance between balls    private static final int DISP = 2 * SIZE;        // x coordinate of the next ball to be drawn    private int ballX = BALL_X;        // the list of all balls    private BallListInterface ballList;        private AudioClip noise;        public void begin() {        // list of balls is empty at first        ballList = new EmptyBallList();        noise = getAudio("pop.wav");    }        // draws a ball and adds it to the list    public void onMousePress(Location point) {        FilledOval ball = new FilledOval(ballX, BALL_Y, SIZE, SIZE, canvas);        ballList = new NonEmptyBallList(ball, ballList);        // update x coordinate for the next ball to be drawn        ballX = ballX - DISP;    }        // cause the balls to begin hitting into each    //  other in a "chain reaction"    public void onMouseExit(Location point) {        if (point.getY() < canvas.getHeight()) {                        new BallMover(ballList, SIZE);        } else {            new ColorfulBallMover(ballList, SIZE, noise);                    }            }}

⌨️ 快捷键说明

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