bricks.java
来自「书籍"Java_面向事件编程"的附带光盘代码」· Java 代码 · 共 37 行
JAVA
37 行
import objectdraw.*;import java.awt.*;// Draws ten brickspublic class Bricks extends WindowController { // position and radius of the moon private static final int MOON_INSET = 50; private static final int MOON_SIZE = 70; // dimensions of a brick private static final double BRICK_HEIGHT = 15 ; private static final double BRICK_WIDTH = 30; // level and spacing of bricks private static final double BRICK_TOP = 285; private static final double BRICK_SPACING = 3; // maximum number of bricks to draw private static final int BRICKS_TOTAL = 10; public void begin() { // draw the moon new FilledOval(MOON_INSET,MOON_INSET,MOON_SIZE,MOON_SIZE,canvas); // draw bricks along the bottom of the canvas double brickPosition = 0; // x coordinate of the next brick double brickCount = 0; // number of bricks drawn so far while ( brickCount < BRICKS_TOTAL ) { new FilledRect(brickPosition, BRICK_TOP, BRICK_WIDTH, BRICK_HEIGHT,canvas); brickPosition = brickPosition + BRICK_WIDTH + BRICK_SPACING; brickCount++; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?