diamond.java

来自「windows画图板.类似于windows自带的画图程序!」· Java 代码 · 共 54 行

JAVA
54
字号
import java.awt.*;

/**
 *
 * @author hysun
 */
public class Diamond extends RectBoundedShape {
    
    private int[] xS;
    private int[] yS;
    
    public Diamond(Color c, Stroke s, int x, int y) {
        super(c, s, x, y);
        xS = new int[4];
        yS = new int[4];
    }
    
    public Diamond() {
        super();
        xS = new int[4];
        yS = new int[4];
    }
        
    public void draw(Graphics2D g) {
        g.setColor(color);
        g.setStroke(stroke);
        int x, y, w, h;
        if (startX > endX) {
            x = endX;
            w = startX - endX;
        } else {
            x = startX;
            w = endX - startX;
        }
        if (startY > endY) {
            y = endY;
            h = startY - endY;
        } else {
            y = startY;
            h = endY - startY;
        }
        xS[0] = x + w/2;
        yS[0] = y;
        xS[1] = x + w;
        yS[1] = y + h/2;
        xS[2] = x + w/2;
        yS[2] = y + h;
        xS[3] = x;
        yS[3] = y + h/2;
        g.drawPolygon(xS, yS, 4);
    }
    
}

⌨️ 快捷键说明

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