public class Grid
extends javax.swing.JFrame
the 2-dimensional world in which all grid programs exist,
having only width and height all grids contain a matrix of Box Objects in which to store their GridItems
|
none...
|
public Box[][] getBoxes()
returns a multidimensional array of Box Objects that make up this grid
public Box getBoxAt(int x, int y)
synonymous with - getBoxes()[x][y]
public int[] findBoxCord(Box b)
returns two integers in the form of {x, y}
where - getBoxAt(x, y) - would return b
public int[] findBoxCord(GridItem i)
throws NullParentBoxException
synonymous with - findBoxCord(i.getParentBox()) -
will throw an exception if i dosn't have a parent Box
public void setBoxes(Box[][] b)
throws WrongGridSizeException
sets all the boxes in the grid to those in the b matrix,
will throw an exception if b's size is different then that of the size of the grid
public void setBoxAt(Box b, int x, int y)
sets the box at (x,y) in the grid to b
public GridActor[] findGridActors()
returns all GridItem Objects that exist on this Grid and are also GridActors
protected void keyWasPressed(int k)
throws GridException
called automatically when a key is pressed down on the keyboard,
causes all GridActors on the Grid to invoke - keyDown(k)
protected void keyWasReleased(int k)
throws GridException
called automatically when a key is released on the keyboard,
causes all GridActors on the Grid to invoke - keyUp(k)
|
public Grid(int x, int y, java.awt.Color t)
creates a grid with a width equal to x, a height equal to y,
and a background color equal to t
public Grid(int x, int y)
same as - new Grid(x, y, new java.awt.Color(0xffffff)); -
setting the background color to white
|
public class Box
extends javax.swing.JLabel
a container for a single GridItem, however one Grid can be made up of multiple Box Objects
|
none...
|
public Grid getParentGrid()
returns the grid that this Box belongs to
public java.awt.Color getTurf()
returns the background color of this Box
public GridItem getGridItem()
returns the GridItem found in this Box, or null if empty
public int[] getBoxCord()
retruns the coordinates of this Box in the form of {x, y} on its parent Grid,
will return null if this Box dosn't belong to a grid
public void addGridItem(GridItem item)
throws ParentBoxIsSetException, GridItemIsDeadException
adds item to this Box, will throw an exception if item already belongs to a Box,
will throw an exception if item has invoked the kill() method
|
public Box(java.awt.Color t)
creates a box with the background color of t
public Box(Color t, GridItem item)
throws ParentBoxIsSetException, GridItemIsDeadException
synonymous with - { Box b = new Box(t); b.addGridItem(item); }
public Box(GridItem item)
throws ParentBoxIsSetException, GridItemIsDeadException
synonymous with - new Box(new java.awt.Color(0xffffff), item); -
setting the new Box's background color to white
public Box()
synonymous with - new Box(new java.awt.Color(0xffffff)) -
setting the new Box's background color to white
|
public abstract class GridItem
items to be placed on the 2D Grid, all GridItem Objects can be placed within a parent Box,
if that Box is on a Grid then the GridItem will display there
|
none...
|
public Box getParentBox()
returns the Box with which this GridItem belongs to
public Grid getParentGrid()
throws NullParentBoxException
synonymous with - this.getParentBox().getParentGrid() - however,
will throw an exception if this.getParentBox() returns null
public javax.swing.ImageIcon getIcon()
returns the ImageIcon Object that represents the icon that displays your GridItem
public String getName()
returns the name of this GridItem,
the name of a GridItem is a String that represents the GridItem,
as well the name will be displayed on hover
public int[] getBoxCord()
throws NullParentBoxException
synonymous with - this.getParentBox().getBoxCord() - however,
will throw an exception if this.getParentBox() returns null
public boolean isAlive()
returns false if this GridItem has ever invoked the kill() method,
else it returns true
public void setIcon(javax.swing.ImageIcon i)
sets the GridItems icon to i
public void setName(String n)
set this GridItem's name to n
public void addToBox(Box b)
throws ParentBoxIsSetException, GridItemIsDeadException
synonymous with - b.addGridItem(this)
public void removeFromGrid()
throws GridItemIsDeadException, NullParentBoxException
removes the GridItem from its parent Box ergo removing it from the Grid,
will throw an exception if the GridItem has even invoked the kill() method,
will throw an exception if the GridItem dosn't belong to any parent Box
public void kill()
used to delete a GridItem and insure it can not be re-placed in any Box
public void revive()
a fail-safe that will allow the GridItem to behave as if kill() was never invoked on it
|
public GridItem(String url, String n)
creates a new GridItem displayed with an icon found at url, and with a name n
public GridItem(String url, String n, Box b)
synonymous with
- { GridItem g = new GridItem(url, n); b.addGridItem(g); } - however,
will never throw ParentBoxIsSetException or GridItemIsDeadException from the addGridItem() method
public GridItem(String url, Box b)
synonymous with - new GridItem(url, "", b);
public GridItem(String url)
synonymous with - new GridItem(url, "");
public GridItem()
synonymous with - new GridItem("grid/default_griditem.dmi"); -
this icon is supplied by the grid package
|
public abstract class MovableGridItem
extends GridItem
as a subclass of GridItem,
a MovableGridItem represents a GridItem that will be capable of moving from Box to Box
as to not be limited to its original parent Box and in turn move around the Grid
|
none...
|
abstract protected void bump(GridItem item)
throws GridException
invoked automatically when this.move() causes the MovableGridItem
to try and move to a Box that already contains another GridItem,
item will have the value of the target Box's GridItem
protected void move(int x, int y)
throws NullParentBoxException, NullParentGridException, GridItemIsDeadException
moves this MovableGridItem x boxes right (east) and y boxes down (south),
this method was made to be called to from within some public method of a subclass of MovableGridItem,
i.e. - Bug b = new Bug(); b.moveNorth(); assuming
public class Bug extends MovableGridItem{ public void moveNorth() { move(0, -1); } } -
will throw an exception if this MovableGridItem is not in a box, if its parent Box is not in a Grid,
or if the MovableGridItem has ever invoked kill()
protected void movedOffGrid()
invoked automatically when this.move() causes the MovableGridItem
to try and move passed the bounds of its parent Grid,
by default it prints a message and then invokes this.kill(),
consider overriding
|
public MovableGridItem(String url, String n, Box b)
calls - super(url, n. b);
public MovableGridItem(String url, String n)
calls - super(url, n);
public MovableGridItem(String url, Box b)
calls - super(url, b);
public MovableGridItem(String url)
calls - super(url);
public MovableGridItem()
calls - super();
|
public interface GridActor
if a GridItem implements this, it can act on events sent from the keyboard to its parent Grid
|
none...
|
public void keyUp(key k)
throws GridException
invoked when a key is released, k has the value of that key
public void keyDown(key k)
throws GridException
invoked when a key is pressed down, k has the value of that key
|
N/A
|