-
Notifications
You must be signed in to change notification settings - Fork 0
/
Group.java
85 lines (78 loc) · 2.04 KB
/
Group.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
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
import java.util.*;
/**
* Write a description of class Group here.
*
* @author
* @version
*/
public class Group extends Point
{
// instance variables - replace the example below with your own
private double scaleFactor;
private ArrayList<Point> objects;
/**
* Constructor
*/
public Group(double dx, double dy){
super(dx, dy);
objects = new ArrayList<Point>();
}
/**
* Adds a copy of the the item
* @param item to be added to group
*/
public void add(Point item){
Point copy = (Point)item.clone();
objects.add(copy);
}
/**
* Draws all Shapes within the Group
*/
public void draw(){
for(Point item : objects){
item.draw();
}
}
/**
* Removes all Shapes of the Group from the screen
*/
public void erase(){
for(Point item : objects){
item.erase();
}
}
/**
* Moves all Shapes in the Group a set amount in x- and y-axis
*/
public void move(double x, double y){
if (getXposition() == 0) {
super.move(x,y);
for(Point item : objects) {
item.move(x + getXposition(),y + getYposition());
}
}
else {
super.move(x,y);
for(Point item : objects){
item.move(x,y);
}
}
}
public void resize(double scaleFactor){
for(Point item : objects){
item.resize(scaleFactor);
}
}
/**
* try-catch statement was not used as CloneNotSupportedException gave a
* "never thrown in body of corresponding try statement"
*/
public Group clone(){
Group copy = (Group)super.clone();
copy.objects = (ArrayList<Point>)objects.clone();
for(int i = 0; i < objects.size(); i++){
copy.objects.set(i, objects.get(i).clone());
}
return copy;
}
}