au.com.solidsoftware.multimahjong.mmc.usergui
Class UserGUI

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--javax.swing.JFrame
                                |
                                +--au.com.solidsoftware.multimahjong.mmc.usergui.UserGUI

public class UserGUI
extends javax.swing.JFrame

This class contains the main method and is responsible for starting a game on the MultiMahjongClient, after which it serves as a centralised compartment for the storage of references to other specialised GUI-related classes.

During the early stages of the program, this class is responsible for displaying internal frames within the desktop pane. Three different internal frames have been envisaged, only one of which may be displayed at any one time:

The above internal frames will obtain information necessary for starting a game on this client. Such information will be obtained locally from the user via input fields, or remotely by connecting to the MultiMahjongServer. A Game object is created with the information obtained.

The UserGUI class then creates the playing screen, which allows the user to interact graphically with the underlying game engine. The playing screen will be an ordinary panel occupying the entire window, in contrast to the internal frames described above. A typical view of the playing screen is shown here:

After all initialisation is completed, the UserGUI class serves as a centralised compartment for the storage and retrieval of references to other specialised GUI-related classes. The advantage of this design is that all the references are kept in the one place, meaning that individual classes do not have to keep a whole list of their own references.

Author:
Victor H. Leung
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JFrame
javax.swing.JFrame.AccessibleJFrame
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AWTTreeLock
 
Field Summary
private  ActionPane actionPane
          A reference to the action pane.
private  javax.swing.JDesktopPane desktop
          A specialised pane for the management of internal frames.
private  Game game
          A reference to the game.
private  GameTypeSelector gameTypeSelector
          A reference to game type selector.
static javax.swing.ImageIcon[] iconList
          An array of all the player icons used in the game.
private static int ICONS
          The number of icons we have in the iconImages/ directory.
private  int limit
          The score limit of the game.
private  PlayArea playArea
          A reference to the play area.
private  Human player
          A reference to the Human object containing information about the user.
private  int progress
          This tracks the loading progress of the game and usergui classes.
private  javax.swing.JProgressBar progressBar
          This shows the progress of the loading of the panes in the playing screen.
private  javax.swing.JLabel progressLabel
          This displays what is actually loading at any given time.
private  StatusPane statusPane
          A reference to the status pane.
private  TabbedPane tabbedPane
          A reference to the tabbed pane.
private  UserGUI userGUI
          A reference to this object.
private  int userID
          The array index that refers to the user's entry in players array.
 
Fields inherited from class javax.swing.JFrame
accessibleContext, defaultCloseOperation, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
base, CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, frameSerializedDataVersion, HAND_CURSOR, icon, ICONIFIED, mbManagement, menuBar, MOVE_CURSOR, N_RESIZE_CURSOR, nameCounter, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, ownedWindows, resizable, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, serialVersionUID, state, SW_RESIZE_CURSOR, TEXT_CURSOR, title, W_RESIZE_CURSOR, WAIT_CURSOR, weakThis
 
Fields inherited from class java.awt.Window
active, base, focusMgr, inputContext, nameCounter, OPENED, ownedWindowList, serialVersionUID, state, warningString, weakThis, windowListener, windowSerializedDataVersion
 
Fields inherited from class java.awt.Container
component, containerListener, containerSerializedDataVersion, dispatcher, layoutMgr, maxSize, ncomponents, serialVersionUID
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, assert, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, hasFocus, height, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, RIGHT_ALIGNMENT, serialVersionUID, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowListenerK, x, y
 
Constructor Summary
UserGUI()
          Creates an instance of UserGUI, initialising and displaying the main application window.
 
Method Summary
 void createGameTypeSelector()
          Creates and displays a new internal frame that allows the user to select the type of game to play, to enter their name and icon, to set the score limit of the game, and to enter the address of the MultiMahjongServer.
 void createMultiGameJoiner(java.lang.String name, int iconID, Registrar registrar)
          Creates and displays a new internal frame that forms a connection to the server and allows the user to select a game to join from a list of available multi player games on the server.
 void createMultiGameStarter(java.lang.String name, int iconID, int limit, Registrar registrar)
          Creates and displays a new internal frame that forms a connection to the server and allows the user to monitor the players that have registered to join the current multi player game.
 Player[] createPlayers(RefereeIntf referee, int playerID, int initScore)
          Retrieves a list of players from the server, and create local Human, ComputerOpponent and Player objects as appropriate.
 void createPlayingScreen(Player[] players)
          Displays the playing screen.
 ActionPane getActionPane()
          Access method - returns a reference to the action pane.
 Game getGame()
          Access method - returns a reference to the game.
 GameTypeSelector getGameTypeSelector()
          Access method - returns a reference to the game type selector.
 PlayArea getPlayArea()
          Access method - returns a reference to the play area.
 Human getPlayer()
          Access method - returns a reference to the Human object containing information about the user.
 StatusPane getStatusPane()
          Access method - returns a reference to the status pane.
 TabbedPane getTabbedPane()
          Access method - returns a reference to the tabbed pane.
static void main(java.lang.String[] args)
          Main method of the MultiMahjongClient application.
 void startGame(RefereeIntf referee, Observer observer, int playerID)
          Creates a multi player game on this client.
 void startGame(java.lang.String name, int iconID, int limit)
          Creates a single player game on this client.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, createRootPaneException, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, processKeyEvent, processWindowEvent, setContentPane, setDefaultCloseOperation, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Frame
, addNotify, addToFrameList, constructComponentName, finalize, getCursorType, getFrames, getIconImage, getMenuBar, getState, getTitle, initIDs, isResizable, postProcessKeyEvent, readObject, remove, removeFromFrameList, removeNotify, setCursor, setIconImage, setMenuBar, setResizable, setState, setTitle, writeObject
 
Methods inherited from class java.awt.Window
addOwnedWindow, addWindowListener, applyResourceBundle, applyResourceBundle, connectOwnedWindow, dispatchEventImpl, dispose, eventEnabled, getFocusOwner, getInputContext, getLocale, getOwnedWindows, getOwner, getToolkit, getWarningString, isActive, isShowing, nextFocus, ownedInit, pack, postEvent, postWindowEvent, preProcessKeyEvent, processEvent, removeOwnedWindow, removeWindowListener, setFocusOwner, setWarningString, show, toBack, toFront, transferFocus
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyOrientation, countComponents, deliverEvent, dispatchEventToSelf, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getMouseEventTarget, getPreferredSize, getWindow, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPrint, list, list, locate, minimumSize, paint, paintComponents, postsOldMouseEvents, preferredSize, print, printComponents, printOneComponent, processContainerEvent, proxyEnableEvents, proxyRequestFocus, remove, remove, removeAll, removeContainerListener, setFont, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getSize, getToolkitImpl, getTreeLock, getWidth, getWindowForObject, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processInputMethodEvent, processMouseEvent, processMouseMotionEvent, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

userGUI

private UserGUI userGUI
A reference to this object.


ICONS

private static final int ICONS
The number of icons we have in the iconImages/ directory.


iconList

public static javax.swing.ImageIcon[] iconList
An array of all the player icons used in the game. This is to be used by all objects requiring access to player icons.


desktop

private javax.swing.JDesktopPane desktop
A specialised pane for the management of internal frames.


gameTypeSelector

private GameTypeSelector gameTypeSelector
A reference to game type selector. We need this so that we can indirectly obtain a reference to the Registrar object on the remote server.

tabbedPane

private TabbedPane tabbedPane
A reference to the tabbed pane.


actionPane

private ActionPane actionPane
A reference to the action pane.


statusPane

private StatusPane statusPane
A reference to the status pane.


playArea

private PlayArea playArea
A reference to the play area.


progress

private int progress
This tracks the loading progress of the game and usergui classes.

progressLabel

private javax.swing.JLabel progressLabel
This displays what is actually loading at any given time.

progressBar

private javax.swing.JProgressBar progressBar
This shows the progress of the loading of the panes in the playing screen.

player

private Human player
A reference to the Human object containing information about the user.


game

private Game game
A reference to the game.


limit

private int limit
The score limit of the game.


userID

private int userID
The array index that refers to the user's entry in players array. Since there are a maximum of four players in a game of Mahjong, this value is in the range [0,3].

Constructor Detail

UserGUI

public UserGUI()
Creates an instance of UserGUI, initialising and displaying the main application window. A WindowListener is added to this window that, upon intercepting a "Close Window" operation from the operating system, displays a dialog box asking the user to confirm their decision to quit the program.

TODO: screenshot of the quit confirmation dialog

The player icon images will then be pre-loaded into an public static array, available for ready retrieval by all methods. Finally, the createGameTypeSelector method is invoked, which creates and displays an internal frame in the centre of main application window.

Method Detail

createGameTypeSelector

public void createGameTypeSelector()
Creates and displays a new internal frame that allows the user to select the type of game to play, to enter their name and icon, to set the score limit of the game, and to enter the address of the MultiMahjongServer. A specialised panel for the management of internal frames, the desktop pane, is first added to the main window. The desktop pane will be filled with a tiled wallpaper image. A new instance of GameTypeSelector is then created and added to the desktop pane. The loading of the GameTypeSelector occurs in a separate thread so that the GUI does not appears "frozen" to the user.


createMultiGameStarter

public void createMultiGameStarter(java.lang.String name,
                                   int iconID,
                                   int limit,
                                   Registrar registrar)
Creates and displays a new internal frame that forms a connection to the server and allows the user to monitor the players that have registered to join the current multi player game. This is accomplished by creating a new instance of MultiGameStarter and adding this to the desktop pane. The loading of the MultiGameStarter occurs in a separate thread so that the GUI does not appears "frozen" to the user.

Parameters:
name - the name of the user
iconID - the iconID of the user
limit - the score limit
registrar - the name of the remote registrar

createMultiGameJoiner

public void createMultiGameJoiner(java.lang.String name,
                                  int iconID,
                                  Registrar registrar)
Creates and displays a new internal frame that forms a connection to the server and allows the user to select a game to join from a list of available multi player games on the server. This is accomplished by creating a new instance of MultiGameJoiner and adding this to the desktop pane. The loading of the GameTypeSelector occurs in a separate thread so that the GUI does not appears "frozen" to the user.

Parameters:
name - the name of the user
iconID - the iconID of the user
registrar - the name of the remote registrar

startGame

public void startGame(java.lang.String name,
                      int iconID,
                      int limit)
Creates a single player game on this client. This method instantiates a new Observer and then sets up a LocalReferee using this new Observer. It then creates a new Game which runs off this LocalReferee. Upon creating each of the four players required for a game (who may be either a Human, ComputerOpponent or Player, the createPlayingScreen method is invoked to create and display the main playing screen.

Parameters:
name - the name of the user
iconID - the iconID of the user
limit - the score limit

startGame

public void startGame(RefereeIntf referee,
                      Observer observer,
                      int playerID)
Creates a multi player game on this client. This method creates a new instance of the Game class with the supplied parameters. The createPlayingScreen method is then invoked to create and display the main playing screen. The generation of computer opponents, the randomisation of the seating posiitons of all the players, and the determination of the initial winds of all the players have already been accomplished - and all this information is present within the players array.

Parameters:
referee - The remote referee.
observer - The local observer.
playerID - The unique player identification number.

createPlayers

public Player[] createPlayers(RefereeIntf referee,
                              int playerID,
                              int initScore)
Retrieves a list of players from the server, and create local Human, ComputerOpponent and Player objects as appropriate. The decision as to the class of the object to be created is based solely on the positions array being obtained from the server.

Parameters:
referee - The local server that simulates the behaviour of the functionality of the remote server.
playerID - The unique player identification number.
initScore - The initial score of each of the four players.

createPlayingScreen

public void createPlayingScreen(Player[] players)
Displays the playing screen. This method is expected to take a while, since each pane in the playing screen is its own class. A progress bar is displayed to inform the user of the loading status of all the classes. The actual loading occurs in a separate thread so that the GUI does not appears "frozen" to the user.

Parameters:
players - An array which stores information specific for each of the players. In this method, we are interested only in extracting the players' names, scores and icons.

getGameTypeSelector

public GameTypeSelector getGameTypeSelector()
Access method - returns a reference to the game type selector.

Returns:
a reference to the game type selector

getTabbedPane

public TabbedPane getTabbedPane()
Access method - returns a reference to the tabbed pane.

Returns:
a reference to the tabbed pane

getActionPane

public ActionPane getActionPane()
Access method - returns a reference to the action pane.

Returns:
a reference to the action pane

getStatusPane

public StatusPane getStatusPane()
Access method - returns a reference to the status pane.

Returns:
a reference to the status pane

getPlayArea

public PlayArea getPlayArea()
Access method - returns a reference to the play area.

Returns:
a reference to the play area

getPlayer

public Human getPlayer()
Access method - returns a reference to the Human object containing information about the user.

Returns:
a reference to the Human object containing information about the user

getGame

public Game getGame()
Access method - returns a reference to the game.

Returns:
a reference to the game

main

public static void main(java.lang.String[] args)
Main method of the MultiMahjongClient application. Sets the look and feel for the application and creates an instance of UserGUI.

Parameters:
args - Any command line arguments supplied. This parameter is ignored by this method.