📄 chainreaction.java~
字号:
import objectdraw.*;// 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.public class ChainReaction extends WindowController { private RandomIntGenerator randomColor = new RandomIntGenerator(0, 255); // 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; public void begin() { // list of balls is empty at first ballList = new EmptyBallList(); } // draws a ball 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) { new BallMover(ballList, SIZE); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -