tipgame.util
Class GameSelector

java.lang.Object
  extended by tipgame.util.GameSelector

public class GameSelector
extends java.lang.Object

this class takes care of connecting networked games.

Author:
Jam Jenkins

Nested Class Summary
private  class GameSelector.GameSelectionListener
          updates the session spinner when a game is selected
private  class GameSelector.JoinGameListener
          joins or starts a game
private  class GameSelector.QuitGameListener
          breaks connection with the server and exits
private  class GameSelector.RefreshGameListListener
          reloads information from the server
 
Field Summary
private  java.util.TreeMap<java.lang.String,java.lang.Class> classes
          map of game name to class that extends GameLoop
private  javax.swing.JFrame frame
          the frame for the GUI
private  javax.swing.JComboBox gameSpinner
          the selection of games on this computer
private  java.io.ObjectInputStream in
          connection from the server
private  javax.swing.JButton joinButton
          the button for starting the game
private  java.io.ObjectOutputStream out
          connection to the server
private  javax.swing.JSpinner playerSpinner
          the option for number of players
private  javax.swing.JButton quitButton
          the button for exit
private  javax.swing.JButton refreshButton
          the button for refreshing information from the server
private  Server server
          server connected to
private  javax.swing.JTextField serverField
          where the user puts the server to connect to
private  java.util.HashMap<java.lang.String,java.util.TreeSet<java.lang.String>> sessions
          map of games to sessions
private  javax.swing.JComboBox sessionSpinner
          the selection of sessions for a given game
 
Constructor Summary
GameSelector()
          initializes the GUI, connects to the server on the local machine and displays the games/sessions running
 
Method Summary
private  void connect()
          connects to the server
static java.lang.String getHostname()
          gets the name of the localhost on the network
private  void join()
          sends the join command to the server
private  void loadGames()
          gets the list of game and sessions from the server
static void main(java.lang.String[] argv)
          makes the GUI and sets up information from the localhost server
private  void makeComponents()
          initializes the components and sets up the listeners
private  void makeLayout()
          lays out the components on a grid in the frame
private  void refresh()
          reads information from the server and updates the listed games and sessions
private  void refreshSpinners()
          refreshes the sessions to match the game
private  void setVisible(boolean vis)
          makes the GUI visible or invisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

frame

private javax.swing.JFrame frame
the frame for the GUI


serverField

private javax.swing.JTextField serverField
where the user puts the server to connect to


gameSpinner

private javax.swing.JComboBox gameSpinner
the selection of games on this computer


sessionSpinner

private javax.swing.JComboBox sessionSpinner
the selection of sessions for a given game


playerSpinner

private javax.swing.JSpinner playerSpinner
the option for number of players


joinButton

private javax.swing.JButton joinButton
the button for starting the game


quitButton

private javax.swing.JButton quitButton
the button for exit


refreshButton

private javax.swing.JButton refreshButton
the button for refreshing information from the server


sessions

private java.util.HashMap<java.lang.String,java.util.TreeSet<java.lang.String>> sessions
map of games to sessions


classes

private java.util.TreeMap<java.lang.String,java.lang.Class> classes
map of game name to class that extends GameLoop


out

private java.io.ObjectOutputStream out
connection to the server


in

private java.io.ObjectInputStream in
connection from the server


server

private Server server
server connected to

Constructor Detail

GameSelector

public GameSelector()
initializes the GUI, connects to the server on the local machine and displays the games/sessions running

Method Detail

setVisible

private void setVisible(boolean vis)
makes the GUI visible or invisible

Parameters:
vis - true means make visible, false means hide

makeLayout

private void makeLayout()
lays out the components on a grid in the frame


refresh

private void refresh()
reads information from the server and updates the listed games and sessions


refreshSpinners

private void refreshSpinners()
refreshes the sessions to match the game


connect

private void connect()
connects to the server


getHostname

public static java.lang.String getHostname()
gets the name of the localhost on the network

Returns:

makeComponents

private void makeComponents()
initializes the components and sets up the listeners


join

private void join()
sends the join command to the server


loadGames

private void loadGames()
gets the list of game and sessions from the server


main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
makes the GUI and sets up information from the localhost server

Parameters:
argv - not used
Throws:
java.lang.Exception - if communications to the server break