-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyOval.java
More file actions
83 lines (75 loc) · 3.29 KB
/
MyOval.java
File metadata and controls
83 lines (75 loc) · 3.29 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package twodimensionaldrawingapplication;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.awt.Graphics;
public class MyOval extends MyShape {
//Oval characteristics
private boolean filled = false;
private int width;
private int height;
//constructor
public MyOval(int x1, int y1, int x2, int y2, Color firstColor, Color secondColor, int lineWidth, boolean gradient, boolean dashed, float dashLength, boolean filled) {
super(x1, y1, x2, y2, firstColor, secondColor, lineWidth, gradient, dashed, dashLength);
this.filled = filled;
}
public boolean isFilled() {
return filled;
}
public boolean isOvalInQuadOne(int x1, int y1, int x2, int y2) { //logic to test where object is being drawn at
return x1 >= x2 && y1 >= y2;
}
public boolean isOvalInQuadTwo(int x1, int y1, int x2, int y2) {
return x2 >= x1 && y1 >= y2;
}
public boolean isOvalInQuadThree(int x1, int y1, int x2, int y2) {
return x1 >= x2 && y2 >= y1;
}
@Override
public void draw(Graphics2D g2d) {
width = getX2() - getX1(); //normal width base case quad 4
height = getY2() - getY1(); //normal height base case quad 4
if (isGradient() == true) {
g2d.setPaint(new GradientPaint(getX1(), getY1(), getFirstColor(), getX2(), getY2(), getSecondColor(), true));
}
else {
g2d.setPaint(getFirstColor());
}
if (isDashed() == true) { //if dashed option is checked
float[] dashLengthArray = {getDashLength()}; //dash length array for dash stroke
g2d.setStroke(new BasicStroke(getLineWidth(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10, dashLengthArray, 0));
}
else {
g2d.setStroke(new BasicStroke(getLineWidth()));
}
if (isFilled() == true) {
if (isOvalInQuadOne(getX1(), getY1(), getX2(), getY2())) {
g2d.fillOval(getX2(), getY2(), getX1() - getX2(), getY1() - getY2());
}
else if (isOvalInQuadTwo(getX1(), getY1(), getX2(), getY2())) {
g2d.fillOval(getX1(), getY2(), getX2() - getX1(), getY1() - getY2());
}
else if (isOvalInQuadThree(getX1(), getY1(), getX2(), getY2())) {
g2d.fillOval(getX2(), getY1(), getX1() - getX2(), getY2() - getY1());
}
else { //quadrant 4 base case
g2d.fillOval(getX1(), getY1(), width, height);
}
}
else {
if (isOvalInQuadOne(getX1(), getY1(), getX2(), getY2())) {
g2d.drawOval(getX2(), getY2(), getX1() - getX2(), getY1() - getY2());
}
else if (isOvalInQuadTwo(getX1(), getY1(), getX2(), getY2())) {
g2d.drawOval(getX1(), getY2(), getX2() - getX1(), getY1() - getY2());
}
else if (isOvalInQuadThree(getX1(), getY1(), getX2(), getY2())) {
g2d.drawOval(getX2(), getY1(), getX1() - getX2(), getY2() - getY1());
}
else { //quadrant 4 base case
g2d.drawOval(getX1(), getY1(), width, height);
}
}
}
}