|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectpackageForLT05.DotModel
public class DotModel
The class encapsulates a data model that consists of an set of a between 2 and 10. The dots are uniquely identified by an integer index. The first dot's identifier is 0, the second's is 1, and so on until the final dot.
Each dot is understood to have a diameter (of a certain number of units, where the actual physical size of the unit is left unspecified and is abstracted away). Each dot is understood to have a location, which is specified as an x, y coordinate in a two-dimensional plane that has its origin in the upper left corner. A two-dimensional plane of 200x600 units is assumed. Each dot is understood to be associated with a color.
Each dot is randomly assigned a position, diameter and color. The positions are chosen randomly from among the visible positions. The diameters are chosen randomly from among the possible values in the interval [50,100]. The colors are chosen randomly from the colors red, blue, and green.
This model is capable of having listeners installed upon it. Anytime this model changes, the listener's changed() method will be invoked.
Constructor Summary | |
---|---|
DotModel(int numberOfDots)
Creates a default version of this data model with the specified number of dots. |
Method Summary | |
---|---|
void |
addListener(DotModelListener listener)
Installs the passed listener on this model. |
void |
changeDiameter(int dotIdentifier,
int newDiameter)
Causes the indicated dot to have a new diameter as specified by the passed value. |
java.awt.Color |
getColour(int dotIdentifier)
Gets the colour that corresponds to the specified dot. |
int |
getDiameter(int dotIdentifier)
Gets the diameter of the specified dot. |
java.awt.geom.Ellipse2D |
getDot(int dotIdentifier)
Gets the dot that corresponds to the specified dot. |
int |
getMaxX()
Gets the maximum horizontal dimension. |
int |
getMaxY()
Gets the maximum vertical dimension. |
int |
getNumberOfDots()
|
void |
nudgeToRight(int dotIdentifier)
Causes the indicated dot to be nudged to the right by a small amount. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DotModel(int numberOfDots) throws java.lang.RuntimeException
numberOfDots
- the number of dots this model should contain. Must be a number
between 2 and 10.
java.lang.RuntimeException
- if the number of dots is invalidMethod Detail |
---|
public void nudgeToRight(int dotIdentifier)
public void changeDiameter(int dotIdentifier, int newDiameter)
public int getMaxX()
public int getMaxY()
public void addListener(DotModelListener listener)
listener
- public int getNumberOfDots()
public java.awt.Color getColour(int dotIdentifier) throws java.lang.RuntimeException
dotIdentifier
- the identifier of the dot
java.lang.RuntimeException
- if the identifier for the dots is invalidpublic int getDiameter(int dotIdentifier)
dotIdentifier
- the identifier of the dot
java.lang.RuntimeException
- if the identifier for the dots is invalidpublic java.awt.geom.Ellipse2D getDot(int dotIdentifier) throws java.lang.RuntimeException
dotIdentifier
- the identifier of the dot
java.lang.RuntimeException
- if the identifier for the dots is invalid
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |