📄 snow.java
字号:
import objectdraw.*;import java.awt.*;import java.applet.*;// Program which creates clouds which create snow, sleet, tomatoes, and cows// when the user clickspublic class Snow extends WindowController { // dimensions and location of the screen private static final int SCREEN_LEFT = 0; private static final int SCREEN_TOP = 0; private static final int SCREEN_HEIGHT = 400; private static final int SCREEN_WIDTH = 500; // constants for the moon size and location private static final int MOON_INSET = 50; private static final int MOON_SIZE = 70; // sizes and locations for the bricks private static final double BRICK_LINE = SCREEN_HEIGHT * 0.85; private static final double BRICK_HEIGHT = SCREEN_HEIGHT * .04; private static final double SKYLINE = BRICK_LINE + BRICK_HEIGHT; private static final double BRICK_WIDTH = 30; private static final double BRICK_SPACING = 3; // colors of the sky, mortar, and brick private final Color NIGHTSKY = new Color(50, 50, 100); private final Color MORTAR = new Color(200, 200, 200); private final Color BRICKRED = new Color(150, 40, 40); private Image snowPic, cow, upsideCow; private AudioClip moo; public void begin() { // where to draw next brick double brickPosition; // get pictures snowPic = getImage("snow.gif"); cow = getImage("cow-small.gif"); upsideCow = getImage("upside-cow.gif"); moo = getAudio("cow.wav"); // draw solid sky, mortar, and moon new FilledRect(0, 0, SCREEN_WIDTH, SKYLINE, canvas).setColor(NIGHTSKY); new FilledRect(0, SKYLINE, SCREEN_WIDTH, SCREEN_HEIGHT - BRICK_LINE, canvas).setColor( MORTAR); new FilledOval(MOON_INSET, MOON_INSET, MOON_SIZE, MOON_SIZE, canvas).setColor(Color.white); // add the bricks brickPosition = 0; while (brickPosition < SCREEN_WIDTH) { new FilledRect(brickPosition, BRICK_LINE, BRICK_WIDTH, BRICK_HEIGHT, canvas).setColor( BRICKRED); brickPosition = brickPosition + BRICK_WIDTH + BRICK_SPACING; } } public void onMouseClick(Location point) { // make a new cloud when the user clicks new Cloud(snowPic, upsideCow, cow, moo, SCREEN_WIDTH, SCREEN_HEIGHT, canvas); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -