|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.byu.phun2d.DrawObj
edu.byu.phun2d.Group
public class Group
A Group collects a series of other DrawObj objects to be drawn, including other GroupObjs. The Group allows a whole collection of drawable things to be manipulated as a whole. This simplifies building up complex scenes of many objects.
To build up a Group one first uses the constructor Group() to create the empty object. If this is added to a window or another Group, nothing will be seen because this group has no contents. The easiest way to provide contents is to add other DrawObj objects (line, rectangle, group etc.) using the add(DrawObj) method. These objects will be drawn in the order that they are added to the group. This means that if any of the objects overlap, the last ones in the group will appear on top.
It is also easy to get the objects that are part of a group. Each object in a group has an index (a number to reference that object). The first object in the group is at index zero, the second is at index 1, and so forth. To get an object use the getObjectAt(index) method. It is also possible to change one of those objects to something else. The setObjectAt(index, object) will change the object at the specified index to some new object. You can find out how many objects there are in a group using the nObjs() method.
Constructor Summary | |
---|---|
Group()
|
Method Summary | |
---|---|
void |
add(DrawObj newObj)
This will add a new object to the list of objects in this group. |
DrawObj |
getObjectAt(int index)
This will get an object from this group. |
int |
nObjs()
This will return the number of objects in this group. |
void |
setFillColor(Color c)
Generates an error message because you cannot change the fill color of a Group. |
void |
setLineColor(Color c)
Generates an error message because you cannot change the line color of a Group. |
void |
setLineWidth(double width)
Generates an error message because you cannot change the line width of a Group. |
void |
setObjectAt(int index,
DrawObj newObj)
This will change one of the existing objects in a group. |
Methods inherited from class edu.byu.phun2d.DrawObj |
---|
getFillColor, getLineColor, getLineWidth, getRotate, getScaleX, getScaleY, getTranslate, insideToOutside, outsideToInside, setRotate, setScale, setTranslate |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Group()
Method Detail |
---|
public void add(DrawObj newObj)
newObj
- the new object to be added.public int nObjs()
public DrawObj getObjectAt(int index)
index
- the index of the object to be retrieved. If this is an invalid
index (less than zero or beyond the end of the list) then null is returned.
public void setObjectAt(int index, DrawObj newObj)
index
- this is the index of the object to be changed. This should
be greater than or equal to zero and less than nObjs().newObj
- This is the new object to be placed at the specified
index. This will replace the old object.public void setFillColor(Color c)
setFillColor
in class DrawObj
c
- the new fill color.public void setLineColor(Color c)
setLineColor
in class DrawObj
c
- the new line/border color.public void setLineWidth(double width)
setLineWidth
in class DrawObj
width
- the new line width.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |