checkers.view
Class NetworkView

java.lang.Object
  extended by java.lang.Thread
      extended by checkers.view.NetworkView
All Implemented Interfaces:
CheckersConstants, java.lang.Runnable, java.util.Observer

public class NetworkView
extends java.lang.Thread
implements java.util.Observer, CheckersConstants

Observes model, and sends any changes over the network. When a change is received, it imitates the GUI by generating the same ActionEvents as if the change happened locally. This makes networking transparent to the controller.

Author:
Peter Kuhn

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int PORT_NUM
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface checkers.CheckersConstants
ACCEPT, BLUE, CLIENTGAME, DRAW, HOST, HOSTGAME, JOIN, KING, LOCAL, LOCALGAME, NUM_SPACES, PLAYER1SET, PLAYER2SET, RESIGN, SINGLE, UPDATE, WHITE
 
Constructor Summary
NetworkView(java.util.Observable a1, java.util.Observable a2, int color)
          Registers Actionlisteners and sets player1color
 
Method Summary
 void addActionListener(java.awt.event.ActionListener a)
          Allows for spoofed Actions to be sent to the controller
 void connectToHost(java.lang.String ip)
          Connects to specified IP address and starts the network thread.
 void hostGame()
          Starts hosting a game and waits for a remote client to connect.
 void run()
          Network thread, sets up the network and receives packets and handles them appropriately.
 void setNetwork()
          Registers networkView with observables.
 void setPlayerName(int num, java.lang.String name)
          Sets the player's name so it can be sent over the network on initial handshake.
 void stopHostListening()
          Cancel Host Listening without closing the program.
 void update(java.util.Observable arg0, java.lang.Object arg1)
          Recievees updates from the model and sends them over the network.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PORT_NUM

public static final int PORT_NUM
See Also:
Constant Field Values
Constructor Detail

NetworkView

public NetworkView(java.util.Observable a1,
                   java.util.Observable a2,
                   int color)
Registers Actionlisteners and sets player1color

Method Detail

connectToHost

public void connectToHost(java.lang.String ip)
Connects to specified IP address and starts the network thread.

Parameters:
ip - ip to connect to

hostGame

public void hostGame()
Starts hosting a game and waits for a remote client to connect.


stopHostListening

public void stopHostListening()
Cancel Host Listening without closing the program.


setNetwork

public void setNetwork()
Registers networkView with observables.


run

public void run()
Network thread, sets up the network and receives packets and handles them appropriately.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

addActionListener

public void addActionListener(java.awt.event.ActionListener a)
Allows for spoofed Actions to be sent to the controller

Parameters:
a - controller

update

public void update(java.util.Observable arg0,
                   java.lang.Object arg1)
Recievees updates from the model and sends them over the network.

Specified by:
update in interface java.util.Observer
Parameters:
arg0 -
arg1 -

setPlayerName

public void setPlayerName(int num,
                          java.lang.String name)
Sets the player's name so it can be sent over the network on initial handshake.

Parameters:
num - player num
name - player name