main
Class EangTermProject

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by javax.swing.JApplet
                      extended by main.EangTermProject
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.WindowListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.MenuListener, javax.swing.RootPaneContainer

public class EangTermProject
extends javax.swing.JApplet
implements javax.swing.event.MenuListener, java.awt.event.ActionListener, java.awt.event.WindowListener

Created on October 27, 2006, 6:01 PM
The main frame for the othello applet.
Sets up the menus and the game board. Also designed to run as a stand alone application.
Refactored: removed the cell array into a seperate panel.
Changed the current player panel to a more specific panel to display additional information not included in the basic othello cell, such as a string "Current player = White" t.5 Made changes to work with changes in communications.
t.6 added control for the sound by adding a sound on menu item checkbox.

Version:
t.6
Author:
Eric Angeli
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JApplet
javax.swing.JApplet.AccessibleJApplet
 
Nested classes/interfaces inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JApplet
accessibleContext, rootPane, rootPaneCheckingEnabled
 
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
EangTermProject()
          Creates a new instance of EangTermProject
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent aevnt)
          Handles menu actions, such as start.
 void configHosting()
          Prompts the user to configure settings for hosting a game.
 void countPieces()
          Counts the pieces on the board and updates the score.
 void createConnectSplash(java.lang.String data)
          Creates a splash that is used while either hosting and waiting or while connecting to a remote host.
 void determineColor(java.lang.String data)
          Determine the players colors.
Called when the host recieves a message to set up the colors.
Parses the message for the number chosen by the opponent, then compares it to a number chosen by the host.
 void disconnect()
          Disconnects from a networked game.
Resets the menus and displays the original intro splash screen.
 void disconnectMessage()
          Displays a message if there was a problem with the network connection.
 void doConnection(java.lang.String connectString)
          Attempts to connect to a remote host given the settings to be used.
 void endGame()
          Ends the game.
Displays a splash panel indicating the outcome of the game.
 void getMyColor()
          Gets the color of the player playing on this board.
Sends a request to the host asking for this players color.
 java.lang.String getOpponnentColor()
          Gets the opponents color.
 java.lang.String getPlayer()
          Gets the players color.
 void init()
          Initializes the applet.
 void initBoard()
          Initializes the gameboard and adds the cells to the panel.
 void initIntroSplash()
          Initializes the splash for the intro, when the game is started.
 void initMenu()
          Sets up the menu.
 void initNetMenu()
          Initializes the network menu.
 void initPlayerSquare()
          Creates and adds the current player panel.
 void initScoreSquare()
          Creates and adds the player score panel.
 void iPlacedPiece()
          Updates the gameboard after a piece is successfully placed on the board.
 boolean isWaitingForColor()
          Gets whether the game is still waiting for the player color to be set.
static void main(java.lang.String[] args)
          The main function that starts the appilication.
 void menuCanceled(javax.swing.event.MenuEvent mevent)
          Handles menu canceled events.
 void menuDeselected(javax.swing.event.MenuEvent mevent)
          Sets the games pause state to the original pause state.
 void menuSelected(javax.swing.event.MenuEvent mevent)
          Pauses the game when a menu is clicked.
 void moveEnemy(java.lang.String enemyPosition)
          Moves the enemy.
Updates the enemies position if over a valid move.
 void newGame()
          Starts a new game.
First tries to remove and stop any existing panels and threads.
Next it recreates the game board and loads the images and initializes the score and current player panels.
 void pauseGame(boolean pg)
          Changes the pause state of the game.
 boolean placeEnemy(java.lang.String enemyPosition)
          Places an enemy/opponent's piece on the game board.
 void removeComms()
          removes the comms panel from the main panel.
 void removeCurrentPlayer()
          removes the currentPlayer panel from the main panel.
 void removeGameBoard()
          removes the gameBoard panel from the main panel.
 void removeIntro()
          Removes the intro panel from the main panel.
 void removeScore()
          removes the scorePanel from the main panel.
 void resetBackground()
          Resets the backgrounds on the game board after a move is made or a piece is placed.
 void resetCurrentPlayer()
          Resets the current player color.
 void sendOpponnentColor()
          Sends the opponents color when requested.
 void sendPlacedPiece(java.awt.Point myPosition)
          Sends the point when a piece is placed on the board.
 void sendPosition(java.awt.Point myPosition)
          Sends the position when the mouse is over a valid move.
 void setActivePlayer()
          Sets the current active player.
Prevents the game board from recieving events if the player is not the players turn.
 void setBoardCheck()
          USED FOR DEBUGGING.
Used to test a possible case when the mouse listeners are not correctly reset.
 void setBoardSkip()
          USED FOR DEBUGGING.
Used to force the white player to have to skip a turn.
 void setCommsConnected(boolean connected)
          Sets the comms connection state.
 void setCurrentPlayer()
          Sets the current player color that is placing a piece on the board.
 void setPanelsVisible(boolean vis)
          Hides the panels so they do not overlap the splash panel.
 void setPlayer(java.lang.String player)
          Sets the player color
Also sets the player color on the Score panel, but only if playing a networked game.
 void setPlayerColor(java.lang.String data)
          Sets the players color.
 void setUpColor()
          Sets up the color when playing a network game.
This is only done by the player connecting to the host.
 void setUpConnection()
          Prompts the user for the connection settings when playing a networked game.
 void setWaitingForColor(boolean waitingForColor)
          Sets if still waiting for the player's color or not.
 void startHosting(java.lang.String connectString)
          Starts up a network socket to wait for a connection.
 boolean stillValidMoves()
          Checks to see if there are still any valid moves.
If the current player does not have any valid moves, then a message is displayed and their turn is skipped. If no valid moves exist for either player, then the game is terminated and the ending splash panel is displayed.
 void stop()
          Stops the game.
Attempts to stop all threads that are currently running.
 void stopComms()
          Stops the communications if the comms thread is not null.
 void stopCurrentPlayer()
          Stops the current player panel thread if it is not null.
 void stopCurrentScore()
          Stops the current score panel thread if it is not null.
 void stopGameBoard()
          Stops the game board if it is not null.
 void stopIntro()
          Stops the splash thread if it is not null.
 void turnSound(boolean soundState)
          Changes the sound state when the sound menu check box item is clicked.
 void updateConnect(java.lang.String updateWith)
          Updates the comms splash panel with a new string.
 void windowActivated(java.awt.event.WindowEvent we)
          Handles the window activated event.
 void windowClosed(java.awt.event.WindowEvent we)
          Handles the window closed event.
 void windowClosing(java.awt.event.WindowEvent we)
          Handles the window closed event.
Stops all threads and disposes of the panels.
 void windowDeactivated(java.awt.event.WindowEvent we)
          Handles the windows deactivated event.
 void windowDeiconified(java.awt.event.WindowEvent we)
          Handles the window deiconified event.
 void windowIconified(java.awt.event.WindowEvent we)
          Handles the window iconified event.
 void windowOpened(java.awt.event.WindowEvent we)
          Handles the window opened event.
 
Methods inherited from class javax.swing.JApplet
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, remove, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.applet.Applet
destroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, 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

EangTermProject

public EangTermProject()
Creates a new instance of EangTermProject

Method Detail

init

public void init()
Initializes the applet.

Overrides:
init in class java.applet.Applet

initMenu

public void initMenu()
Sets up the menu.


initNetMenu

public void initNetMenu()
Initializes the network menu.


initIntroSplash

public void initIntroSplash()
Initializes the splash for the intro, when the game is started.


initBoard

public void initBoard()
Initializes the gameboard and adds the cells to the panel.


initScoreSquare

public void initScoreSquare()
Creates and adds the player score panel.


initPlayerSquare

public void initPlayerSquare()
Creates and adds the current player panel.


pauseGame

public void pauseGame(boolean pg)
Changes the pause state of the game.

Parameters:
pg - The new pause state of the game.

stop

public void stop()
Stops the game.
Attempts to stop all threads that are currently running.

Overrides:
stop in class java.applet.Applet

stopGameBoard

public void stopGameBoard()
Stops the game board if it is not null.


stopCurrentPlayer

public void stopCurrentPlayer()
Stops the current player panel thread if it is not null.


stopCurrentScore

public void stopCurrentScore()
Stops the current score panel thread if it is not null.


stopComms

public void stopComms()
Stops the communications if the comms thread is not null.


stopIntro

public void stopIntro()
Stops the splash thread if it is not null.


disconnect

public void disconnect()
Disconnects from a networked game.
Resets the menus and displays the original intro splash screen.


disconnectMessage

public void disconnectMessage()
Displays a message if there was a problem with the network connection.


createConnectSplash

public void createConnectSplash(java.lang.String data)
Creates a splash that is used while either hosting and waiting or while connecting to a remote host.

Parameters:
data - The string to be displayed in the splash panel.

removeIntro

public void removeIntro()
Removes the intro panel from the main panel.


removeGameBoard

public void removeGameBoard()
removes the gameBoard panel from the main panel.


removeCurrentPlayer

public void removeCurrentPlayer()
removes the currentPlayer panel from the main panel.


removeScore

public void removeScore()
removes the scorePanel from the main panel.


removeComms

public void removeComms()
removes the comms panel from the main panel.


newGame

public void newGame()
Starts a new game.
First tries to remove and stop any existing panels and threads.
Next it recreates the game board and loads the images and initializes the score and current player panels.


endGame

public void endGame()
Ends the game.
Displays a splash panel indicating the outcome of the game.


setCurrentPlayer

public void setCurrentPlayer()
Sets the current player color that is placing a piece on the board.


resetCurrentPlayer

public void resetCurrentPlayer()
Resets the current player color.


countPieces

public void countPieces()
Counts the pieces on the board and updates the score.


stillValidMoves

public boolean stillValidMoves()
Checks to see if there are still any valid moves.
If the current player does not have any valid moves, then a message is displayed and their turn is skipped. If no valid moves exist for either player, then the game is terminated and the ending splash panel is displayed.

Returns:
True if there are still valid moves, otherwise false.

setPanelsVisible

public void setPanelsVisible(boolean vis)
Hides the panels so they do not overlap the splash panel.

Parameters:
vis - Whether the panels are visible or not.

configHosting

public void configHosting()
Prompts the user to configure settings for hosting a game.


startHosting

public void startHosting(java.lang.String connectString)
Starts up a network socket to wait for a connection.

Parameters:
connectString - The string containing setup information for the comms configuration.

updateConnect

public void updateConnect(java.lang.String updateWith)
Updates the comms splash panel with a new string.

Parameters:
updateWith - The string to update the splash panel with.

setUpConnection

public void setUpConnection()
Prompts the user for the connection settings when playing a networked game.


doConnection

public void doConnection(java.lang.String connectString)
Attempts to connect to a remote host given the settings to be used.

Parameters:
connectString - A string containing the settings to be used when trying to connect to a remote host.

sendPosition

public void sendPosition(java.awt.Point myPosition)
Sends the position when the mouse is over a valid move.

Parameters:
myPosition - A point representig the current position over

sendPlacedPiece

public void sendPlacedPiece(java.awt.Point myPosition)
Sends the point when a piece is placed on the board.

Parameters:
myPosition - The point of the piece placed on the board.

setUpColor

public void setUpColor()
Sets up the color when playing a network game.
This is only done by the player connecting to the host.


determineColor

public void determineColor(java.lang.String data)
Determine the players colors.
Called when the host recieves a message to set up the colors.
Parses the message for the number chosen by the opponent, then compares it to a number chosen by the host.

Parameters:
data - A string containing the number chosen by the opponent, ie the player connecting to the host.

getMyColor

public void getMyColor()
Gets the color of the player playing on this board.
Sends a request to the host asking for this players color.


sendOpponnentColor

public void sendOpponnentColor()
Sends the opponents color when requested.


getOpponnentColor

public java.lang.String getOpponnentColor()
Gets the opponents color.

Returns:
The opponents color as a string

setPlayerColor

public void setPlayerColor(java.lang.String data)
Sets the players color.

Parameters:
data - The new player's color.

setCommsConnected

public void setCommsConnected(boolean connected)
Sets the comms connection state.

Parameters:
connected - Whether comms is connected or not.

iPlacedPiece

public void iPlacedPiece()
Updates the gameboard after a piece is successfully placed on the board.


setPlayer

public void setPlayer(java.lang.String player)
Sets the player color
Also sets the player color on the Score panel, but only if playing a networked game.

Parameters:
player - The player's color.

getPlayer

public java.lang.String getPlayer()
Gets the players color.

Returns:
The players color.

resetBackground

public void resetBackground()
Resets the backgrounds on the game board after a move is made or a piece is placed.


setActivePlayer

public void setActivePlayer()
Sets the current active player.
Prevents the game board from recieving events if the player is not the players turn.


moveEnemy

public void moveEnemy(java.lang.String enemyPosition)
Moves the enemy.
Updates the enemies position if over a valid move.

Parameters:
enemyPosition - The enemies new position.

placeEnemy

public boolean placeEnemy(java.lang.String enemyPosition)
Places an enemy/opponent's piece on the game board.

Parameters:
enemyPosition - The position the enemy placed a piece.
Returns:
True if successfully placed, otherwise false.

turnSound

public void turnSound(boolean soundState)
Changes the sound state when the sound menu check box item is clicked.

Parameters:
soundState - The new sound state.

menuCanceled

public void menuCanceled(javax.swing.event.MenuEvent mevent)
Handles menu canceled events.

Specified by:
menuCanceled in interface javax.swing.event.MenuListener
Parameters:
mevent - The menu event canceled.

menuSelected

public void menuSelected(javax.swing.event.MenuEvent mevent)
Pauses the game when a menu is clicked.
Keeps the menu list from being painted over.

Specified by:
menuSelected in interface javax.swing.event.MenuListener
Parameters:
mevent - The menu selected.

menuDeselected

public void menuDeselected(javax.swing.event.MenuEvent mevent)
Sets the games pause state to the original pause state.

Specified by:
menuDeselected in interface javax.swing.event.MenuListener
Parameters:
mevent - The menu unselcted.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent aevnt)
Handles menu actions, such as start.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
aevnt - The event fired.

setBoardSkip

public void setBoardSkip()
USED FOR DEBUGGING.
Used to force the white player to have to skip a turn.


setBoardCheck

public void setBoardCheck()
USED FOR DEBUGGING.
Used to test a possible case when the mouse listeners are not correctly reset.


windowDeactivated

public void windowDeactivated(java.awt.event.WindowEvent we)
Handles the windows deactivated event.

Specified by:
windowDeactivated in interface java.awt.event.WindowListener
Parameters:
we - The window event.

windowActivated

public void windowActivated(java.awt.event.WindowEvent we)
Handles the window activated event.

Specified by:
windowActivated in interface java.awt.event.WindowListener
Parameters:
we - The source of the window event.

windowDeiconified

public void windowDeiconified(java.awt.event.WindowEvent we)
Handles the window deiconified event.

Specified by:
windowDeiconified in interface java.awt.event.WindowListener
Parameters:
we - The source of the window event.

windowIconified

public void windowIconified(java.awt.event.WindowEvent we)
Handles the window iconified event.

Specified by:
windowIconified in interface java.awt.event.WindowListener
Parameters:
we - The source of the window event.

windowClosing

public void windowClosing(java.awt.event.WindowEvent we)
Handles the window closed event.
Stops all threads and disposes of the panels.

Specified by:
windowClosing in interface java.awt.event.WindowListener
Parameters:
we - The source of the window event.

windowClosed

public void windowClosed(java.awt.event.WindowEvent we)
Handles the window closed event.

Specified by:
windowClosed in interface java.awt.event.WindowListener
Parameters:
we - The source of the window event.

windowOpened

public void windowOpened(java.awt.event.WindowEvent we)
Handles the window opened event.

Specified by:
windowOpened in interface java.awt.event.WindowListener
Parameters:
we - The source of the window event.

isWaitingForColor

public boolean isWaitingForColor()
Gets whether the game is still waiting for the player color to be set.

Returns:
True if still waiting for the color, otherwise false.

setWaitingForColor

public void setWaitingForColor(boolean waitingForColor)
Sets if still waiting for the player's color or not.

Parameters:
waitingForColor - True if still waiting, false otherwise.

main

public static void main(java.lang.String[] args)
The main function that starts the appilication.

Parameters:
args - An array of arguments passed into main.