-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSquare.java
58 lines (49 loc) · 1.22 KB
/
Square.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
47
48
49
50
51
52
53
54
55
56
57
import java.awt.Color;
import java.awt.Graphics;
/**
* Write a description of class Circle here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Square extends AbstractShape
{
private int side;
private boolean changeAspect;
public Square(int side, Color color){
this.side = side;
this.color = color;
}
public Square(int x, int y){
this.x = x;
this.y = y;
color = getNextColor();
side = 25;
}
public int getSide(){
return side;
}
public void draw(Graphics g, int x, int y){
this.draw(g);
this.x=x;
this.y =y;
}
public void draw(Graphics g){
g.setColor(color);
g.fillRect(x, y, side, side);
}
public void clickAt(int x, int y){
changeAspect = contains(x, y);
if(changeAspect){
color = getNextColor();
changeAspect =false;
side = (int)(200 * Math.random());
}
}
public boolean contains(int x, int y){
int xCenter = this.x;
int yCenter = this.y;
double d = Math.hypot(yCenter - y, xCenter - x);
return (d <= side);
}
}