-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyLine.java
46 lines (37 loc) · 1.51 KB
/
MyLine.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GradientPaint;
import java.awt.BasicStroke;
import java.awt.geom.Line2D;
public class MyLine extends MyShape {
// constructor without input values
public MyLine() {
super();
}
// constructor with input values
public MyLine( int x1, int y1, int x2, int y2, float strokeWidth, float dashLength, Color color, Color color2,
boolean gradient,boolean dashed ) {
super(x1, y1, x2, y2, strokeWidth, dashLength, color, color2, gradient, dashed);
}
// Actually draws the line
public void draw( Graphics g ) {
Graphics2D g2 = ( Graphics2D )g;
if (getGradient()){ // if gradient option is selected
GradientPaint gradientPaint = new GradientPaint(getX1(),getY1(), getColor(),getX2(),getY2(),getColor2());
g2.setPaint(gradientPaint);
}
else
g2.setPaint(getColor());
if (getDashed()){ // if dashed line option is selected
float dash1[] = {10.0f};
BasicStroke dashedLine = new BasicStroke(getDashLength(),BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
g2.setStroke(dashedLine);
}
else {
g2.setStroke(new BasicStroke(getStrokeWidth()));
}
g2.draw( new Line2D.Float( getX1(), getY1(), getX2(), getY2()) );
}
}