Get RobotChase at Fast, secure and Free Open Source software downloads

Class RCView

  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.gcs.robot.RCView
All Implemented Interfaces:
ActionListener, MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener, Observer, Accessible

public class RCView
extends JPanel
implements ActionListener, MouseListener, MouseMotionListener, Observer

The RCView class is the main view of the game board. It observes the game model and determines what to draw on each square, delegating the actual drawing to RCTile. The view also implements MouseListener and MouseMotionListener, as an alternative to keyboard input. If animation is enabled, a timer moves the player as far as possible at a rate determined by DELAY.

John B. Matthews
See Also:
RCModel, RCTile

Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
Nested classes/interfaces inherited from class java.awt.Container
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
Field Summary
Fields inherited from class javax.swing.JComponent
Fields inherited from class java.awt.Component
Fields inherited from interface java.awt.image.ImageObserver
Constructor Summary
RCView(RCModel game)
          Construct a view of the specified game board.
Method Summary
 void actionPerformed(ActionEvent e)
          Animate one move; stop when no more moves or game won.
 int getHeightInPixels()
          Return the view height in pixels.
 int getHeightInTiles()
          Return the view height in tiles.
 Dimension getPreferredSize()
          Return this panel's preferred size based on tile geometry.
 int getWidthInPixels()
          Return the view width in pixels.
 int getWidthInTiles()
          Return the view width in tiles.
 void mouseClicked(MouseEvent e)
          Handle mouseClicked events (unused).
 void mouseDragged(MouseEvent e)
          Handle mouseDragged events.
 void mouseEntered(MouseEvent e)
          Handle mouseEntered events to set the cursor.
 void mouseExited(MouseEvent e)
          Handle mouseExited events to restore the cursor.
 void mouseMoved(MouseEvent e)
          Handle mouseMoved events (unused).
 void mousePressed(MouseEvent e)
          Handle mousePressed events.
 void mouseReleased(MouseEvent e)
          Handle mouseReleased events.
 void nextSet()
          Display another set of game tiles.
 void paintComponent(Graphics g)
          Draw a grid and tell each tile to repaint itself.
 void resizeArray(int width, int height)
          Resize the game and view.
 void toggleAnimated()
          Toggle the animation feature.
 void update(Observable model, Object arg)
          Determine what to draw on each tile, then repaint.
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, 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, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, 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, imageUpdate, 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, toString, transferFocus, transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail


public RCView(RCModel game)
Construct a view of the specified game board.

game - a game board
Method Detail


public void resizeArray(int width,
                        int height)
Resize the game and view. Resize the game board, create a conformal view and initialize it.

width - board width measured in tiles
height - board height measured in tiles


public Dimension getPreferredSize()
Return this panel's preferred size based on tile geometry.

getPreferredSize in class JComponent


public int getWidthInTiles()
Return the view width in tiles.


public int getHeightInTiles()
Return the view height in tiles.


public int getWidthInPixels()
Return the view width in pixels.


public int getHeightInPixels()
Return the view height in pixels.


public void update(Observable model,
                   Object arg)
Determine what to draw on each tile, then repaint.

Specified by:
update in interface Observer


public void nextSet()
Display another set of game tiles.


public void paintComponent(Graphics g)
Draw a grid and tell each tile to repaint itself.

paintComponent in class JComponent


public void mouseClicked(MouseEvent e)
Handle mouseClicked events (unused).

Specified by:
mouseClicked in interface MouseListener


public void mouseEntered(MouseEvent e)
Handle mouseEntered events to set the cursor.

Specified by:
mouseEntered in interface MouseListener


public void mouseExited(MouseEvent e)
Handle mouseExited events to restore the cursor.

Specified by:
mouseExited in interface MouseListener


public void mousePressed(MouseEvent e)
Handle mousePressed events.

Specified by:
mousePressed in interface MouseListener


public void mouseReleased(MouseEvent e)
Handle mouseReleased events.

Specified by:
mouseReleased in interface MouseListener


public void mouseMoved(MouseEvent e)
Handle mouseMoved events (unused).

Specified by:
mouseMoved in interface MouseMotionListener


public void mouseDragged(MouseEvent e)
Handle mouseDragged events.

Specified by:
mouseDragged in interface MouseMotionListener


public void actionPerformed(ActionEvent e)
Animate one move; stop when no more moves or game won.

Specified by:
actionPerformed in interface ActionListener


public void toggleAnimated()
Toggle the animation feature.

Get RobotChase at Fast, secure and Free Open Source software downloads

Copyright © 2007 Gem City Software. Distributed under the terms of the GPL