📄 line.java
字号:
/* * Line.java * * Created on April 29, 2005, 5:30 PM */package hysun.draw;import java.awt.*;import java.awt.event.MouseEvent;/** * * @author hysun */public class Line extends RectBoundedShape { public Line(Color c, Stroke s, int x, int y) { super(c, s, x, y); } /** * Line object doesn't follow the cursor event processing specifed by its * superclass GeometryShape. * The difference lies in the processing when shift mask is present. * Line will not always regulate its bounding rectangle to a square. * There will be three cases: the bounding rectangle is either square, * a horizontal line or a vertical line, depending the slope of the line. * * tan(30) = 0.577; * tan(60) = 1.155; */ public void processCursorEvent(MouseEvent e, int t) { if (t != IShape.CURSOR_DRAGGED) return; int x = e.getX(); int y = e.getY(); if (e.isShiftDown()) { if (x - startX == 0) { //vertical endX = startX; endY = y; } else { float slope = Math.abs(((float) (y - startY)) / (x - startX)); if (slope < 0.577) { //horizontal endX = x; endY = startY; } else if (slope < 1.155) { //deg45 regulateShape(x, y); } else { //vertical endX = startX; endY = y; } } } else { endX = x; endY = y; } } public void draw(Graphics2D g) { g.setColor(color); g.setStroke(stroke); g.drawLine(startX, startY, endX, endY); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -