rectangle.java

来自「还不错的java基本实例」· Java 代码 · 共 65 行

JAVA
65
字号
/*
 * 创建日期 2006-1-29
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
package ch4;
public class Rectangle {
    private int x ;
    private int y ;
    private int width ;
    private int height ;

    public  Rectangle(){
        x = 5;
        y = 10;
        width = 50;
        height = 25;
    }
    

    public void setX(int ax ){
        x = ax;
    } 
    public int getX() {
        return x;
    }

    public void setY(int ay){
        x = ay;
    }
    public int getY() {
        return y;
    }

    public void setWidth(int awidth ){
        width = awidth;
    }
    public int getWidth() {
        if (width > 0) 
            return width;
        else
            return 0;
    }

    public void setHeight(int aheight){
        height = aheight;
    }
    public int getHeight() {
        return height;
    }

    public void offset(int ax , int ay ){
        x = x + ax;
        y = y + ay;
    }

    public static void Inflate(Rectangle rec  , int inwidth , int inheight ){
        rec.x = rec.x - inwidth;
        rec.y = rec.y - inheight;
        rec.height = rec.height + 2 * inheight;
        rec.width = rec.width + 2 * inwidth;
    }
}

⌨️ 快捷键说明

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