-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
157 lines (117 loc) · 3.58 KB
/
Rectangle.java
File metadata and controls
157 lines (117 loc) · 3.58 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//Jason Zhou
//Mr. Mouradov
//AP CS Lv 1
// 3/14/21
//importing libraries for future reference
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
//rectangle class for making rectangles on the Custom Panel
public class Rectangle implements Comparable {
//Mouradov just has a color and a y value
/*
int x1, y1, width, height;
Color c;
static int currentX = 0;
static int currentY = 0;
static int rValue = 0;
*/
//creating class variables for future use
private Color c;
private int y;
private boolean selected;
private boolean swap;
private static int swapCount = 0;
private static int delay = 0;
public Rectangle() //default constuctor for the Rectangle object, sets the corner coordinates for the shape
{
//makes a square
y = 0;
c = new Color(0, 0, 0);
selected = false;
swap = false;
swapCount = 0;
delay = 1000;
}
public Rectangle(int y, Color c) //constructor for simply adding rectangles
{
this.y = y;
this.c = c;
selected = false;
swap = false;
delay = 1000;
swapCount = 0;
//currentX += width;
}
public Rectangle(int y, Color c, boolean selected, boolean swap, int delay, int swapCount) //all parameter constructor for the Rectangle class
{
this.y = y;
this.c = c;
this.selected = selected;
this.swap = swap;
this.swapCount = swapCount;
this.delay = delay;
}
public static int getDelay() { //getter that gets the delay static variable
return delay;
}
public Color getC() { //getter that gets the Color of the rectangle object
return c;
}
public int getY() { //getter that gets the y-coordinate of the rectangle object
return y;
}
public static int getSwapCount() { //getter that gets the variable "swapCount"
return swapCount;
}
public boolean isSwap() { //getter that gets the variable "swap"
return swap;
}
public boolean isSelected() { //getter that gets the variable "selected"
return selected;
}
public void setY(int y) { //setter that sets the y-coordinate of the rectangle object
this.y = y;
}
public void setSelected(boolean selected) { //setter that sets the variabke "selected"
this.selected = selected;
}
public void setSwap(boolean swap) { //setter that sets the variable "swap"
this.swap = swap;
}
public void setC(Color c) { //setter that sets the color of the rectangle object
this.c = c;
}
public static void setSwapCount(int swapCount) { //setter that sets the variable "swapCount"
Rectangle.swapCount = swapCount;
}
public static void setDelay(int delay) { //setter that sets the delay static variable
Rectangle.delay = delay;
}
public void flash(JFrame frame, Rectangle other) //causes the rectangle to flash
{
for (int i = 0; i < 6; i++) //repeats the flashing process a total of six times
{
this.swap = !swap; //switches the swap variable from false to true and vice versa
other.setSwap(!other.isSwap()); //switches the swap variable from false to true and vice versa
frame.repaint(); //refreshes the page so the see can see the flashing
try { //delays the code by 1/10th of a second
Thread.sleep(delay);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
swapCount++; //increases swapCount by 1
}
@Override
public int compareTo(Object arg0) { //creates a way to compare rectangles, compares by their r-value for their color
// TODO Auto-generated method stub
if (this.c.getRed() > ((Rectangle)arg0).getC().getRed())
return 1;
else if (this.c.getRed() < ((Rectangle)arg0).getC().getRed())
return -1;
else
return 0;
}
}