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

📄 grass.java

📁 书籍"Java_面向事件编程"的附带光盘代码
💻 JAVA
字号:
import objectdraw.*;import java.awt.*;// Class that draws a grassy scenepublic class Grass extends WindowController {        // level of the horizon    private static final int GROUND_LINE = 270;        // position and radius of the sun    private static final int SUN_INSET = 50,                                   SUN_SIZE = 75;    // level and spacing of the blades of grass    private static final int GRASS_TOP = 255,                             GRASS_SPACING = 3;    public void begin() {        // draw solid ground and sun        new FilledRect(0, GROUND_LINE, canvas.getWidth(),                       canvas.getHeight()-GROUND_LINE, canvas );        new FilledOval(SUN_INSET, SUN_INSET, SUN_SIZE, SUN_SIZE,                       canvas);                // add the blades of grass        double bladePosition = 0; // where to draw next blade of grass        while ( bladePosition < canvas.getWidth() ) {            new Line(bladePosition,GRASS_TOP,bladePosition,GROUND_LINE,                     canvas);            bladePosition = bladePosition + GRASS_SPACING;        }    }}

⌨️ 快捷键说明

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