diamond.java
来自「java编写的最好的画图板程序」· Java 代码 · 共 56 行
JAVA
56 行
/* * Diamond.java * * Created on April 29, 2005, 5:37 PM */package hysun.draw;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 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 + -
显示快捷键?