📄 cloud.java
字号:
import objectdraw.*;import java.awt.*;import java.applet.*;// Modified to produce some snow, sleet, tomatoes, and cowspublic 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; // for the cow private Image upsideDownCow, cow; private AudioClip moo; // size of the screen private int screenWidth, screenHeight; // used to generate random speeds and positions for snowflakes private RandomIntGenerator objGen; public Cloud( Image aSnowPic, Image cow, Image upsideCow, AudioClip moo, int aScreenWidth, int aScreenHeight, DrawingCanvas aCanvas) { // save the parameters for the "run" method canvas = aCanvas; snowPic = aSnowPic; upsideDownCow = upsideCow; this.cow = cow; this.moo = moo; screenWidth = aScreenWidth; screenHeight = aScreenHeight; objGen = 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, tomatoes, or cows, randomly switch (objGen.nextValue() % 4) { case 0 : new FallingSnow(canvas, snowPic, objGen.nextValue(), // x coordinate objGen.nextValue() * 2 / screenWidth + 2, // y speed screenHeight); break; case 1 : new FallingSleet( canvas, objGen.nextValue(), objGen.nextValue() * 4 / screenWidth + 2, screenHeight); break; case 2 : new FallingTomato( canvas, objGen.nextValue(), objGen.nextValue() * 4 / screenWidth + 2, screenHeight); break; case 3 : new FallingCow( canvas, cow, upsideDownCow, moo, objGen.nextValue() %(canvas.getWidth() - 100), screenHeight); break; } pause(PAUSETIME); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -