rushhour
Class RushHourVehicle

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by rushhour.RushHourVehicle
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.SwingConstants

public class RushHourVehicle
extends javax.swing.JLabel

A vehicle must be either a car or a truck. It can be placed on the game board and its (vehicleX, vehicleY) coordinates can be shifted depending on its horizontal or vertical orientation. Vehicles contain a unique ID, which represents the order in which they were added to the game board, and a unique hash ID, which combines their unique ID with their (vehicleX, vehicleY) coordinate index on the game board.

Vehicles can also be distinguished by their color. Two vehicles should not have the same color, but the vehicle object does no assurance checking to make sure a vehicle of the specified color does not already exist.

Cars have a vehicleLength of two (2) and trucks have a vehicleLength of three (3). All vehicles have a vehicleWidth of one (1).

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLabel
javax.swing.JLabel.AccessibleJLabel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JLabel
labelFor
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
RushHourVehicle(RushHourGameBoard gameBoard, int uniqueID, java.lang.String type, java.lang.String color, java.lang.String orientation, int x, int y)
          Construct a vehicle that can be placed on the game board.
 
Method Summary
 java.lang.String getColor()
          Retrieve the color of the vehicle.
 java.lang.String getHashID()
          Retrieve the hash ID for the vehicle.
 java.lang.String getOrientation()
          Retrieve the orientation of the vehicle.
 java.lang.String getType()
          Retrieve the type of the vehicle.
 int getUniqueID()
          Retrieve the unique ID of the vehicle.
 int getVehicleIconLength()
          Retrieve the vehicle icon length.
 int getVehicleIconWidth()
          Retrieve the vehicle icon boardWidth.
 int getVehicleLength()
          Retrieve the length of the vehicle.
 int getVehicleWidth()
          Retrieve the boardWidth of the vehicle.
 int getVehicleX()
          Retrieve the x-coordinate of the vehicle.
 int getVehicleY()
          Retrieve the y-coordinate of the vehicle.
 void paintComponent(java.awt.Graphics g)
          The paintComponent() method is overriden to encroprate alpha (composite) manipulation to the 2D graphics.
 void resetIconImage()
          Reset the icon image to the default image for this vehicle.
 void setComposite(float composite)
          Set the alpha (composite) of the vehicle.
 void setUniqueID(int uniqueID)
          Set the unique ID of the vehicle to a new unique ID.
 void setVehicleX(int x)
          Set the new vehicleX-coordinate of the vehicle.
 void setVehicleY(int y)
          Set the new y-coordinate of the vehicle.
 java.lang.String toString()
          A string representation of the vehicle, which is the uniqe identification number.
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RushHourVehicle

public RushHourVehicle(RushHourGameBoard gameBoard,
                       int uniqueID,
                       java.lang.String type,
                       java.lang.String color,
                       java.lang.String orientation,
                       int x,
                       int y)
                throws InvalidVehicleColorException,
                       InvalidVehicleException,
                       RedCarException,
                       OffGameBoardException,
                       VehicleOverlapException
Construct a vehicle that can be placed on the game board.

Parameters:
gameBoard - The game board object. If a null game board object is passed, the object will not be aligned on the GUI, nor will the icon image be assigned.
uniqueID - The unique number that represents this car on the board (represents the sequence in which the vehicle was added to the board.)
type - The type of the new vehicle.
color - The color of the new vehicle.
orientation - The orientation of the new vehicle.
x - The x-coordinate of the new vehicle.
y - The y-coordinate of the new vehicle.
Throws:
InvalidVehicleColorException - The specified vehicle color is either null or already exists on another vehicle on the game board.
InvalidVehicleException - The vehicle was placed improperly.
OffGameBoardException - The specified coordinates are off the game board.
RedCarException - The red car must be in the third row so it can exit.
VehicleOverlapException - The vehicle is placed at coordinates that cause it to overlap an already existing vehicle.
Method Detail

setComposite

public void setComposite(float composite)
Set the alpha (composite) of the vehicle. After setting the composite, call repaint() on the vehicle to make the change appear on the interface. Give the composite a floating number between 0.0 and 1.0.

Parameters:
composite - The new composite.

paintComponent

public void paintComponent(java.awt.Graphics g)
The paintComponent() method is overriden to encroprate alpha (composite) manipulation to the 2D graphics. To set the alpha of this vehicle, call setComposite(), assing the composite to a float between 0.0 and 1.0, then call repaint() on the vehicle. Do not call this method directly. Instead, use repaint().

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - The graphics of the vehicle.

resetIconImage

public void resetIconImage()
Reset the icon image to the default image for this vehicle. Also resets the opacity of the image.


getHashID

public java.lang.String getHashID()
Retrieve the hash ID for the vehicle.

Returns:
The hash ID that represents the vehicle and its location on the board.

getUniqueID

public int getUniqueID()
Retrieve the unique ID of the vehicle.

Returns:
The unique ID of the vehicle.

setUniqueID

public void setUniqueID(int uniqueID)
Set the unique ID of the vehicle to a new unique ID.

Parameters:
uniqueID - The new unique ID.

getType

public java.lang.String getType()
Retrieve the type of the vehicle. Returns "car" or "truck".

Returns:
The type of the vehicle.

getColor

public java.lang.String getColor()
Retrieve the color of the vehicle.

Returns:
The color of the vehicle.

getOrientation

public java.lang.String getOrientation()
Retrieve the orientation of the vehicle. Returns "h" for horizontal and "v" for vertical.

Returns:
The orientation of the vehicle.

getVehicleX

public int getVehicleX()
Retrieve the x-coordinate of the vehicle.

Returns:
The x-coordinate of the vehicle.

setVehicleX

public void setVehicleX(int x)
                 throws OffGameBoardException
Set the new vehicleX-coordinate of the vehicle. Vehicles have no knowledge of other vehicles on the game board, so the game board handles checks for vehicle overlap.

Parameters:
x - The new vehicleX-coordinate of the vehicle.
Throws:
OffGameBoardException - The specified coordinates are off the game board.

getVehicleY

public int getVehicleY()
Retrieve the y-coordinate of the vehicle.

Returns:
The y-coordinate of the vehicle.

setVehicleY

public void setVehicleY(int y)
                 throws OffGameBoardException
Set the new y-coordinate of the vehicle. Vehicles have no knowledge of other vehicles on the game board, so the game board handles checks for vehicle overlap.

Parameters:
y - The new y-coordinate of the vehicle.
Throws:
OffGameBoardException - The specified coordinates are off the game board.

getVehicleLength

public int getVehicleLength()
Retrieve the length of the vehicle.

Returns:
The length of the vehicle.

getVehicleIconLength

public int getVehicleIconLength()
Retrieve the vehicle icon length.

Returns:
The length of the icon of the vehicle.

getVehicleWidth

public int getVehicleWidth()
Retrieve the boardWidth of the vehicle.

Returns:
The boardWidth of the vehicle.

getVehicleIconWidth

public int getVehicleIconWidth()
Retrieve the vehicle icon boardWidth.

Returns:
The boardWidth of the icon of the vehicle.

toString

public java.lang.String toString()
A string representation of the vehicle, which is the uniqe identification number.

Overrides:
toString in class java.awt.Component
Returns:
The string representation of the vehicle.