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

📄 fallingobject.java

📁 书籍"Java_面向事件编程"的附带光盘代码
💻 JAVA
字号:
import objectdraw.ActiveObject;import objectdraw.Drawable2DInterface;// FallingObject class to encapsulate the behavior of ActiveObjects that// fall until they reach a certain y-position then disappearpublic class FallingObject extends ActiveObject {        protected static final int DELAY_TIME = 33;        // Fall until we get to this position    protected int fallToPos;        // how fast?    protected double ySpeed;        // what is falling?    protected Drawable2DInterface object;        // Constructor    // Parameters: thePos - how far down the object should fall    //             theSpeed - how far to fall each time around    public FallingObject(int thePos, double theSpeed) {                ySpeed = theSpeed;        fallToPos = thePos;                // note that it is the responsibility of the derived class        // to call start();    }        // The run method    public void run() {                while (object.getY() < fallToPos) {                        pause(DELAY_TIME);            object.move(0, ySpeed);        }        object.removeFromCanvas();    }}

⌨️ 快捷键说明

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