-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
60 lines (50 loc) · 1.71 KB
/
Rectangle.java
File metadata and controls
60 lines (50 loc) · 1.71 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
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 Rectangle extends Shape{
private double height;
private double width;
public Rectangle ( double iwidth, double iheight, Color ioutlineColor ,Color ifillColor,double ioutlineWidth, double iposx, double iposy ){
this.width = iwidth;
this.height = iheight;
this.outlineColor = ioutlineColor;
this.fillColor = ifillColor;
this.outlineWidth = ioutlineWidth;
this.posx = iposx;
this.posy = iposy;
}
public void setWidth ( double amount ){ this.width = amount; }
public void setheight ( double amount ) { this.height = amount; }
public double getWidth ( ) { return width; }
public double getheight ( ) { return height; }
public double area( ) {
return height * width;
}
public String toString()
{
return "Rectangle width = " + width + " height = " + height + " at { " + posx + " , " + posy + " )";
}
@Override
public boolean contains(double x, double y) {
return x >= posx && x <= posx + width &&
y >= posy && y <= posy + height;
}
@Override
public void draw(GraphicsContext gc) {
if (rightselected == true){
gc.setStroke(Color.RED);
gc.setLineWidth(outlineWidth + 2);
} else {
gc.setStroke(outlineColor);
gc.setLineWidth(outlineWidth);
}
gc.setFill(fillColor);
gc.fillRect(posx, posy, width, height); // Draw the filled rectangle
gc.strokeRect(posx, posy, width, height); // Draw the outline
}
}