fallingtomato.java~

来自「书籍"Java_面向事件编程"的附带光盘代码」· JAVA~ 代码 · 共 47 行

JAVA~
47
字号
import java.awt.Color;import objectdraw.DrawingCanvas;import objectdraw.FilledOval;// FallingSleet classpublic class FallingTomato extends FallingObject {        // size of a sleet pellet        private static final int SIZE = 40;        private static final int SPLATTER_DELAY = 1000;        private DrawingCanvas canvas;        // initialize the instance variables and start the active object        public FallingTomato(DrawingCanvas theCanvas, double x, double aSpeed, int aScreenHeight) {                // first, call "up" to the constructor of the FallingObject class                super(aScreenHeight - SIZE / 2, aSpeed);                canvas = theCanvas;                object = new FilledOval(x, -SIZE, SIZE, SIZE, canvas);                object.setColor(Color.RED);                start();        }        // we override the hitBottom method from FallingObject    // since we want extra functionality        protected void hitBottom() {                // first, remember our x position                double x = object.getX();                object.removeFromCanvas();                // but then a little extra                FilledOval splat =                         new FilledOval(x - SIZE / 2, fallToPos, SIZE * 2,                                                    SIZE / 2, canvas);                splat.setColor(Color.red);                pause(SPLATTER_DELAY);                splat.removeFromCanvas();        }}

⌨️ 快捷键说明

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