thegame.client
Class GameField

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--thegame.client.GameField
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class GameField
extends javax.swing.JPanel

The gamefield. Holds a fixed amount of GameSquares and methods to control their look and behaviour.

Version:
0.99 (2000/08/28)
Author:
Erki Suurjaak
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
static int FIELD_SIZE
          The size of gameField.
protected  GameSquare[][] gameField
          The gamefield.
protected  boolean isChanged
          Is true if the local player has made a move and the isChanged() method has not been called yet; is false otherwise.
protected  boolean isDrawingCircles
          Is true if the local player is drawing circles; is false if the local player is drawing crosses.
protected  boolean isFinished
          Is true if the local player has made a winning move; is false otherwise.
protected  boolean isLocalPlayerLastMoveHighlighted
          Is true if the local player's last move is to be highlighted; is false otherwise.
protected  boolean isLocalPlayerMove
          Is true if the local player can make a move; is false otherwise.
protected  boolean isRemotePlayerLastMoveHighlighted
          Is true if the remote player's last move is to be highlighted; is false otherwise.
protected  int[] localPlayerLastMove
          Holds the coordinates of the last move by the local player.
protected  java.awt.event.ActionListener ON_GAME_SQUARE_CLICK
          The ActionListener for all the GameSquares.
protected  int[] remotePlayerLastMove
          Holds the coordinates of the last move by the remote player.
static int SQUARE_SIZE
          The size of a GameSquare in pixels.
static int SQUARES_TO_WIN
          The minimum amount of squares in row needed for winning.
protected  int[][] winningSquares
          Holds the winning squares if a winning move has been made.
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
GameField(boolean isDrawingCircles)
          Constructs a GameField.
 
Method Summary
 int[][] findWinningSquares(int[] position)
          Finds a winning row around the specified position.
 int[] getMove()
          Returns the coordinates of the last move made by the local player.
 int[][] getWinningSquares()
          Returns the coordinates of the winning squares, or null if the local player has made no winning move.
 boolean isChanged()
          Returns the isChanged property.
 boolean isFinished()
          Returns the isFinished property.
 void reset(boolean enabled)
          Resets the gamefield.
 void setClosed()
          Closes the gamefield.
 void setEnabled(boolean isEnabled)
          Enables or disables user input.
 void setLocalPlayerLastSquareHighlighted(boolean isHighlighted)
          Sets whether or not the last square that the local player clicked on is to be highlighted.
 void setRemotePlayerClickedSquare(int[] square)
          Sets the specified square clicked by the remote player.
 void setRemotePlayerLastSquareHighlighted(boolean isHighlighted)
          Sets whether or not the last square that the remote player clicked on is to be highlighted.
 void setWinningSquares(int[][] squares)
          Marks the specified squares as a winning row and highlights them in a special way.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getWidth, getVisibleRect, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FIELD_SIZE

public static final int FIELD_SIZE
The size of gameField.

gameField

protected GameSquare[][] gameField
The gamefield.

isChanged

protected boolean isChanged
Is true if the local player has made a move and the isChanged() method has not been called yet; is false otherwise.

isDrawingCircles

protected boolean isDrawingCircles
Is true if the local player is drawing circles; is false if the local player is drawing crosses.

isFinished

protected boolean isFinished
Is true if the local player has made a winning move; is false otherwise.

isLocalPlayerLastMoveHighlighted

protected boolean isLocalPlayerLastMoveHighlighted
Is true if the local player's last move is to be highlighted; is false otherwise.

isLocalPlayerMove

protected boolean isLocalPlayerMove
Is true if the local player can make a move; is false otherwise.

isRemotePlayerLastMoveHighlighted

protected boolean isRemotePlayerLastMoveHighlighted
Is true if the remote player's last move is to be highlighted; is false otherwise.

localPlayerLastMove

protected int[] localPlayerLastMove
Holds the coordinates of the last move by the local player.

ON_GAME_SQUARE_CLICK

protected final java.awt.event.ActionListener ON_GAME_SQUARE_CLICK
The ActionListener for all the GameSquares.

remotePlayerLastMove

protected int[] remotePlayerLastMove
Holds the coordinates of the last move by the remote player.

SQUARE_SIZE

public static final int SQUARE_SIZE
The size of a GameSquare in pixels.

SQUARES_TO_WIN

public static final int SQUARES_TO_WIN
The minimum amount of squares in row needed for winning.

winningSquares

protected int[][] winningSquares
Holds the winning squares if a winning move has been made.
Constructor Detail

GameField

public GameField(boolean isDrawingCircles)
Constructs a GameField.
Parameters:
isDrawingCircles - true if the local player is drawing circles; false if the local player is drawing crosses
Method Detail

findWinningSquares

public int[][] findWinningSquares(int[] position)
Finds a winning row around the specified position.
Parameters:
position - the position to be searched around
Returns:
the winning row with positiom as the first element; or null if a winning row could not be found

getMove

public int[] getMove()
Returns the coordinates of the last move made by the local player.
Returns:
the coordinates of the last move

getWinningSquares

public int[][] getWinningSquares()
Returns the coordinates of the winning squares, or null if the local player has made no winning move.
Returns:
the coordinates of the winning squares

isChanged

public boolean isChanged()
Returns the isChanged property. Sets the property false after calling.
Returns:
the isChanged property

isFinished

public boolean isFinished()
Returns the isFinished property.
Returns:
the isFinished property

reset

public void reset(boolean enabled)
Resets the gamefield. Empties all the squares.
Parameters:
enabled - true if user input is allowed; false if user input is forbidden

setClosed

public void setClosed()
Closes the gamefield. Changes the icon of the empty, unclicked squares and disables user input.

setEnabled

public void setEnabled(boolean isEnabled)
Enables or disables user input. Does not disable the squares, but modifies their behaviour to mimic disabled squares, as disabling hundreds of squares at once takes a noticeable time.
Overrides:
setEnabled in class javax.swing.JComponent
Parameters:
isEnabled - true if user input is allowed; false if user input is forbidden

setLocalPlayerLastSquareHighlighted

public void setLocalPlayerLastSquareHighlighted(boolean isHighlighted)
Sets whether or not the last square that the local player clicked on is to be highlighted.
Parameters:
isHighlighted - true if the last square is to be highlighted; false if the last square is not to be highlighted

setRemotePlayerClickedSquare

public void setRemotePlayerClickedSquare(int[] square)
Sets the specified square clicked by the remote player.
Parameters:
square - the square clicked

setRemotePlayerLastSquareHighlighted

public void setRemotePlayerLastSquareHighlighted(boolean isHighlighted)
Sets whether or not the last square that the remote player clicked on is to be highlighted.
Parameters:
isHighlighted - true if the last square is to be highlighted; false if the last square is not to be highlighted

setWinningSquares

public void setWinningSquares(int[][] squares)
Marks the specified squares as a winning row and highlights them in a special way.
Parameters:
squares - the squares to be marked