-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOvalShape.java
More file actions
40 lines (39 loc) · 1.74 KB
/
Copy pathOvalShape.java
File metadata and controls
40 lines (39 loc) · 1.74 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
/*
* ===============================================================================
* OvalShape.java : A shape that is an oval.
* NAME: JANHAV KHANNA
* YOUR UPI: JKHA639
* DATE: 20/05/21
* DESCRIPTION: This is the oval shape class which handles the values and drawing of the shape Oval.
* =============================================================================== */
import java.awt.*;
class OvalShape extends Shape {
/** constructor to create an oval with default values */
public OvalShape() { super(); }
public OvalShape(int x, int y, int width, int height, int marginwidth, int marginheight, Color bordercolor, Color fillcolor, PathType pathtype){
super(x, y, width, height, marginwidth, marginheight, bordercolor, fillcolor, pathtype);
}
public OvalShape(int x, int y, int width, int height, int marginwidth, int marginheight, Color bordercolor, Color fillcolor, PathType pathtype, String t){
super(x, y, width, height, marginwidth, marginheight, bordercolor, fillcolor, pathtype, t);
}
/** draw the oval with the fill colour
* If it is selected, draw the handles
* @param g the Graphics control */
@Override
public void draw(Painter g2d) {
g2d.setPaint(fillColor);
g2d.fillOval(x, y, width, height);
g2d.setPaint(borderColor);
g2d.drawOval(x, y, width, height);
}
/** Returns whether the point is in the oval or not
* @return true if and only if the point is in the oval, false otherwise. */
@Override
public boolean contains(Point mousePt) {
double dx, dy;
Point EndPt = new Point(x + width, y + height);
dx = (2 * mousePt.x - x - EndPt.x) / (double) width;
dy = (2 * mousePt.y - y - EndPt.y) / (double) height;
return dx * dx + dy * dy < 1.0;
}
}