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

📄 cloud.java~

📁 书籍"Java_面向事件编程"的附带光盘代码
💻 JAVA~
字号:
import objectdraw.*;import java.awt.*;// Modified to produce some snow, sleet, and tomatoespublic class Cloud extends ActiveObject {        // total number of falling objects    private static final int MAX_OBJECTS = 150;    // how long to pause between creating objects    private static final int PAUSETIME = 900;        // the canvas    private DrawingCanvas canvas;              // picture of a snowflake    private Image snowPic;          // size of the screen    private int screenWidth, screenHeight;        // used to generate random speeds and positions for falling objects    private RandomIntGenerator snowGen;          public Cloud( Image aSnowPic,                  int aScreenWidth, int aScreenHeight,                   DrawingCanvas aCanvas) {                // save the parameters for the "run" method        canvas = aCanvas;        snowPic = aSnowPic;        screenWidth = aScreenWidth;        screenHeight = aScreenHeight;                snowGen = new RandomIntGenerator( 0, screenWidth);                start();    }        public void run() {        int objCount = 0;                // continue creating objects until the maximum amount        // has been created        while (objCount < MAX_OBJECTS ) {                        objCount++;                        // create snow, sleet or tomatoes, randomly            switch (snowGen.nextValue() % 3) {            case 0:                new FallingSnow(canvas, snowPic,                                 snowGen.nextValue(),   // x coordinate                                snowGen.nextValue()*2/screenWidth+2, // y speed                                screenHeight);                break;            case 1:                new FallingSleet(canvas, snowGen.nextValue(),                                 snowGen.nextValue()*4/screenWidth+2,                                 screenHeight);                break;            case 2:                new FallingTomato(canvas, snowGen.nextValue(),                                  snowGen.nextValue()*4/screenWidth+2,                                  screenHeight);                break;            }            pause(PAUSETIME);        }    }}

⌨️ 快捷键说明

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