Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.jdwsoftware.wfh.control
Class GameComponent  view GameComponent download GameComponent.java

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended bycom.jdwsoftware.wfh.control.GameComponent
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class GameComponent
extends javax.swing.JComponent

Title: Woody's Fishing Hole

Description: Educational Fishing Game

Copyright: Copyright (C) 2003 JDW Software, LLC

Company: JDW Software, LLC

This is the heart of the game. This component displays most of the graphics, handles game logic, creates fish, pretty much all the logic for the game.

This class consists of 2 major parts, the main class which sets up all the graphics figures out how many fish are displayed, paints the fish and handles events. The second is a seperate thread that calculates movement for the fish. The calculations are done on a seperate thread in an attempt to not slow down the redrawing thread. In general, since the fish won't be moving very fast there is no synchronization, if things are off they'll be right hopefully in 1/5 of a second...

Version:
$Revision: 1.8 $

Nested Class Summary
private  class GameComponent.CalculationThread
           
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  java.awt.Image _background
           
private  GameComponent.CalculationThread _calcThread
           
private  com.jdwsoftware.wfh.model.GameType _currentGame
           
private  com.jdwsoftware.wfh.model.Fish _enteringFish
           
private  com.jdwsoftware.wfh.model.Fish _exittingFish
           
private  com.jdwsoftware.wfh.model.Fish[] _fishes
           
private  int _fishHeight
           
private  java.awt.Image[] _fishImages
           
private  int _fishWidth
           
private  int _gameType
           
private  int _height
           
private  java.awt.Image _hook
           
private  int _numFish
           
private  boolean _paused
           
private  javax.swing.JLabel _statusBar
           
private  java.awt.Image[] _upFishImages
           
private  int _width
           
private static float CEILING
           
private static java.lang.String COPYRIGHT
           
private static int DEFAULT_NUM_FISH
           
private static long DELAY
           
private static java.lang.String[] GAME_TYPES
           
private static int GT_COLOR
           
private static int GT_MATH
           
private static int GT_NUM
           
private static int MAX_FISH
           
private  java.awt.Point mouseLoc
           
private  java.util.Random r
           
private static java.lang.String VERSION
           
 
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.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
GameComponent()
          Default constructor
 
Method Summary
 int getNumFish()
          Get the current number of fish being displayed
 java.awt.Dimension getPreferredSize()
          Get the preferred size of this component.
private  void loadCurrentGame()
           
 void notifyMouseClicked(java.awt.Point p)
          Handle a mouse click.
 void notifyMouseMoved(java.awt.Point p)
          Keep track of the current mouse location by being notified of mouse movements here.
protected  void paintComponent(java.awt.Graphics g)
          Paint the component's body.
 void pauseGame(boolean pause)
           
 void setGameType(java.lang.String gameType)
          Set the game type and then invalidate the current game so a new game can be created
 void setNumFish(int numFish)
          Set the number of fish to display.
 void setStatusBar(javax.swing.JLabel statusBar)
          If the main component has a status bar, it should register that status bar here so messages can be displayed.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, 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, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, 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, 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, processMouseEvent, 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, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COPYRIGHT

private static final java.lang.String COPYRIGHT
See Also:
Constant Field Values

VERSION

private static final java.lang.String VERSION
See Also:
Constant Field Values

DELAY

private static final long DELAY
See Also:
Constant Field Values

GT_COLOR

private static final int GT_COLOR
See Also:
Constant Field Values

GT_NUM

private static final int GT_NUM
See Also:
Constant Field Values

GT_MATH

private static final int GT_MATH
See Also:
Constant Field Values

MAX_FISH

private static final int MAX_FISH
See Also:
Constant Field Values

DEFAULT_NUM_FISH

private static final int DEFAULT_NUM_FISH
See Also:
Constant Field Values

GAME_TYPES

private static final java.lang.String[] GAME_TYPES

CEILING

private static final float CEILING
See Also:
Constant Field Values

_paused

private boolean _paused

_background

private java.awt.Image _background

_hook

private java.awt.Image _hook

_fishImages

private java.awt.Image[] _fishImages

_upFishImages

private java.awt.Image[] _upFishImages

mouseLoc

private java.awt.Point mouseLoc

r

private java.util.Random r

_fishes

private com.jdwsoftware.wfh.model.Fish[] _fishes

_enteringFish

private com.jdwsoftware.wfh.model.Fish _enteringFish

_exittingFish

private com.jdwsoftware.wfh.model.Fish _exittingFish

_statusBar

private javax.swing.JLabel _statusBar

_width

private int _width

_height

private int _height

_fishWidth

private int _fishWidth

_fishHeight

private int _fishHeight

_gameType

private int _gameType

_numFish

private int _numFish

_currentGame

private com.jdwsoftware.wfh.model.GameType _currentGame

_calcThread

private GameComponent.CalculationThread _calcThread
Constructor Detail

GameComponent

public GameComponent()
Default constructor

Method Detail

setStatusBar

public void setStatusBar(javax.swing.JLabel statusBar)
If the main component has a status bar, it should register that status bar here so messages can be displayed.


loadCurrentGame

private void loadCurrentGame()

pauseGame

public void pauseGame(boolean pause)

paintComponent

protected void paintComponent(java.awt.Graphics g)
Description copied from class: javax.swing.JComponent
Paint the component's body. This usually means calling ComponentUI.update(java.awt.Graphics, javax.swing.JComponent)>ComponentUI.update(java.awt.Graphics, javax.swing.JComponent) 55 on the JComponent.ui>JComponent.ui 55 property of the component, if it is non-null. You may override this if you wish to customize the component's body-painting behavior. The component's body is painted first, before the border and children.


getPreferredSize

public java.awt.Dimension getPreferredSize()
Get the preferred size of this component.


notifyMouseMoved

public void notifyMouseMoved(java.awt.Point p)
Keep track of the current mouse location by being notified of mouse movements here.


setGameType

public void setGameType(java.lang.String gameType)
Set the game type and then invalidate the current game so a new game can be created


notifyMouseClicked

public void notifyMouseClicked(java.awt.Point p)
Handle a mouse click. If the click happens on a fish with the correct answer, start the correct answer actions.


getNumFish

public int getNumFish()
Get the current number of fish being displayed


setNumFish

public void setNumFish(int numFish)
Set the number of fish to display. Also resets any current fish.