cloud.java~
来自「书籍"Java_面向事件编程"的附带光盘代码」· JAVA~ 代码 · 共 72 行
JAVA~
72 行
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 + =
减小字号Ctrl + -
显示快捷键?