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

📄 visrectangle.java

📁 正在学习Java的人或许能从中得到自己想要的东西
💻 JAVA
字号:
import java.awt.*;

public class visRectangle {
    int x, y, w, h;    //package protected
    private Rectangle rect;
    private boolean selected;

    public visRectangle(int xpt, int ypt) {
        x = xpt;   y = ypt;
        w = 40;    h = 30;
        saveAsRect();
    }
    //-------------------------------------------
    public void setSelected(boolean b) {
        selected = b;
    }
    //-------------------------------------------
    private void saveAsRect() {
        rect = new Rectangle(x-w/2, y-h/2, w, h);
    }
    //-------------------------------------------
    public void draw(Graphics g) {
        g.drawRect(x, y, w, h);
        if (selected) {
            g.fillRect(x+w/2, y-2, 4, 4);
            g.fillRect(x-2, y+h/2, 4, 4);
            g.fillRect(x+w/2, y+h-2, 4, 4);
            g.fillRect(x+w-2, y+h/2, 4, 4);
        }
    }
    //-------------------------------------------
    public boolean contains(int x, int y) {
        return rect.contains(x, y);
    }
    //-------------------------------------------
    public void move(int xpt, int ypt) {
        x = xpt; y = ypt;
        saveAsRect();
    }
}


⌨️ 快捷键说明

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