-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircle.java
More file actions
63 lines (53 loc) · 1.95 KB
/
Circle.java
File metadata and controls
63 lines (53 loc) · 1.95 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
import javafx.scene.paint.Color;
import javafx.scene.canvas.GraphicsContext;
/**
* Write a description of class Circle here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Circle extends Shape{
private double radius;
private final double PI = 3.14159;
public Circle ( double iradius,Color ioutlineColor ,Color ifillColor,double ioutlineWidth, double iposx, double iposy ){
this.radius = iradius;
this.outlineColor = ioutlineColor;
this.fillColor = ifillColor;
this.outlineWidth = ioutlineWidth;
this.posx = iposx;
this.posy = iposy;
}
public void setRadius (double amount ) { this.radius = amount;}
public double getRadius ( ) { return radius; }
public double area( ) { return PI * radius * radius; }
public double circumference( ) { return 2 * PI * radius;}
public boolean equals (Circle c) {
if (this.radius == c.radius)
return true;
return false;
}
public String toString(){ return "Circle radius = " + radius + " at { " + posx + " , " + posy + " )"; }
@Override
public boolean contains(double x, double y) {
// Check if the point (x, y) is within the bounds of the circle
double centerX = posx + radius;
double centerY = posy + radius;
double distanceSquared = (x - centerX) * (x - centerX) + (y - centerY) * (y - centerY);
return distanceSquared <= radius * radius;
}
@Override
public void draw(GraphicsContext gc) {
if (rightselected) {
gc.setStroke(Color.RED);
gc.setLineWidth(outlineWidth + 2);
} else {
gc.setStroke(outlineColor);
gc.setLineWidth(outlineWidth);
}
gc.setFill(fillColor);
// Draw the filled circle
gc.fillOval(posx, posy, radius * 2, radius * 2);
// Draw the outline
gc.strokeOval(posx, posy, radius * 2, radius * 2);
}
}