fang
Class GameWindow

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 fang.GameWindow
All Implemented Interfaces:
ActionListener, WindowStateListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer
Direct Known Subclasses:
FrameAdvancer

public abstract class GameWindow
extends JApplet
implements ActionListener, WindowStateListener

Driver for the GameLoop. Extending this class will put the AnimationCanvas of the the GameLoop into a JFrame with controls at the bottom for starting/pausing, muting, showing a help screen, and quitting.

Author:
Jam Jenkins
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JApplet
JApplet.AccessibleJApplet
 
Nested classes/interfaces inherited from class java.applet.Applet
Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  CardLayout cards
          the layout for the applet/application
protected  FunButton connectButton
           
protected  Container container
          the container need for flipping cards
protected  boolean createOwnFrame
          determines if the game should have its own frame
static boolean displayControlButtons
           
protected  JFrame frame
          frame for the GUI
 boolean fullScreen
          determines if the game will be displayed full screen or not.
protected  HTMLDisplay help
          display for help information
protected  ButtonSprite helpPlay
          control buttons
protected  JLabel loadingMessage
          the message displayed while loading
protected  ButtonSprite mute
          control buttons
protected  ButtonSprite pause
          control buttons
 int players
          the number of players
 boolean playersSelectable
          the ability to change the number of players
protected  JTextField playersSpinner
          input component for the number of players
protected  ButtonSprite quit
          control buttons
protected  JTextField serverField
          input component for the server name
protected  JTextField serverLabel
          labels for connecting in multiplayer games
 boolean serverSelectable
          the ability to change the server name
protected  FunComboBox sessionComboBox
          input component for the session name
protected  JTextField sessionLabel
          labels for connecting in multiplayer games
 boolean sessionSelectable
          the ability to change the session name
protected  JLabel title
          title at the top of the frame
 
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
GameWindow()
          makes the components, layout, and sets the name of the game
 
Method Summary
 void actionPerformed(ActionEvent e)
          responds to control button presses
abstract  void begin()
          starts the game.
abstract  void disconnect()
          abstract method, disconnects
abstract  AnimationCanvas getCanvas()
          abstract method to return canvas
protected  Dimension getDefaultSize()
          if the size is not specified it is 400 x 400
abstract  String getGameName()
          gets the name of the game
 String getHash()
          hashes the compiled source code in order to make sure that the only game which one can connect to is the exact same game.
protected  URL getHelpStyleSheet()
          gets the stylesheet to format the help screen.
static String getHostname()
          gets the name of the localhost on the network
abstract  String getServerName()
          gets the name of the server to connect to when joining a game.
abstract  String getSessionName()
          gets the name of the session.
 void init()
          sets the frame visible
protected  boolean isCreatingOwnFrame()
           
protected  void pauseToggle()
          toggles pause
 void runAsApplication()
          runs as an application.
protected  void setCreateOwnFrame(boolean createOwnFrame)
          Set the createOwnFrame field; true means that when the GameWindow is created, it will create its own top-level window.
protected  void setDefaultHelp()
          sets the default help screen to say that the player should email the author of the game asking him/her to make a help screen
abstract  void setGameName(String name)
          abstract method, sets the name of the game
 void setHelp(String filename)
          this method must be called in order to set the help screen.
 void setHelpText(String helpText)
           
 void setLoadMessage(String message)
          sets a custom loading message
abstract  void setNumberOfPlayers(int players)
          sets the number of players to wait for when starting a new game.
abstract  void setServerName(String server)
          where this game's server resides
abstract  void setSessionName(String session)
          sets the name of this particular instance of the game
 void setTitle(String topTitle)
          Sets the title at the top of the JFrame and/or applet
abstract  void startGame()
          abstract method, starts game
 void stop()
          sets the frame invisible and pauses the game
protected  void toggleAudible()
          toggles the sound between on and muted
 void windowStateChanged(WindowEvent event)
          exits the application when the window closes and also terminates the server connections
 
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
 

Field Detail

frame

protected JFrame frame
frame for the GUI


loadingMessage

protected JLabel loadingMessage
the message displayed while loading


sessionLabel

protected JTextField sessionLabel
labels for connecting in multiplayer games


serverLabel

protected JTextField serverLabel
labels for connecting in multiplayer games


cards

protected CardLayout cards
the layout for the applet/application


container

protected Container container
the container need for flipping cards


pause

protected ButtonSprite pause
control buttons


quit

protected ButtonSprite quit
control buttons


helpPlay

protected ButtonSprite helpPlay
control buttons


mute

protected ButtonSprite mute
control buttons


connectButton

protected FunButton connectButton

sessionComboBox

protected FunComboBox sessionComboBox
input component for the session name


serverField

protected JTextField serverField
input component for the server name


playersSpinner

protected JTextField playersSpinner
input component for the number of players


title

protected JLabel title
title at the top of the frame


help

protected HTMLDisplay help
display for help information


createOwnFrame

protected boolean createOwnFrame
determines if the game should have its own frame


players

public int players
the number of players


playersSelectable

public boolean playersSelectable
the ability to change the number of players


serverSelectable

public boolean serverSelectable
the ability to change the server name


sessionSelectable

public boolean sessionSelectable
the ability to change the session name


displayControlButtons

public static boolean displayControlButtons

fullScreen

public boolean fullScreen
determines if the game will be displayed full screen or not. This variable is only used for applications and must be set prior to calling runAsApplication

Constructor Detail

GameWindow

public GameWindow()
makes the components, layout, and sets the name of the game

Method Detail

setCreateOwnFrame

protected void setCreateOwnFrame(boolean createOwnFrame)
Set the createOwnFrame field; true means that when the GameWindow is created, it will create its own top-level window. Set by the constructor and runAsApplication. Note; this has no meaning after init is called.

Parameters:
createOwnFrame - should the GameWindow create its own top-level window/frame and embed itself there? true means create own frame; false means use applet space set aside in browser

isCreatingOwnFrame

protected boolean isCreatingOwnFrame()

runAsApplication

public void runAsApplication()
runs as an application. This opens up the game in a new window.


setGameName

public abstract void setGameName(String name)
abstract method, sets the name of the game

Parameters:
name - name of game

getGameName

public abstract String getGameName()
gets the name of the game

Returns:
the name of the game

setTitle

public void setTitle(String topTitle)
Sets the title at the top of the JFrame and/or applet

Parameters:
topTitle - the text for the title

setNumberOfPlayers

public abstract void setNumberOfPlayers(int players)
sets the number of players to wait for when starting a new game. Calls to this method are ignored for already started game sessions.

Parameters:
players - the number of players to wait for before starting the game

setServerName

public abstract void setServerName(String server)
where this game's server resides

Parameters:
server - the name of the computer where the game was originally started

setSessionName

public abstract void setSessionName(String session)
sets the name of this particular instance of the game

Parameters:
session - the name of this particular instance of the game

actionPerformed

public void actionPerformed(ActionEvent e)
responds to control button presses

Specified by:
actionPerformed in interface ActionListener

toggleAudible

protected void toggleAudible()
toggles the sound between on and muted


disconnect

public abstract void disconnect()
abstract method, disconnects


pauseToggle

protected void pauseToggle()
toggles pause


setHelp

public void setHelp(String filename)
this method must be called in order to set the help screen. The filename is relative to the class which makes the call. Only what is between the body tags will be displayed, and the full html specs are not supported. Therefore use only simple html in order to make the help display properly.

Parameters:
filename - the relative file name of the help html file

setHelpText

public void setHelpText(String helpText)

setDefaultHelp

protected void setDefaultHelp()
sets the default help screen to say that the player should email the author of the game asking him/her to make a help screen


getHelpStyleSheet

protected URL getHelpStyleSheet()
gets the stylesheet to format the help screen. The default stylesheet is black with blue lettering.

Returns:
the stylesheet to use

getDefaultSize

protected Dimension getDefaultSize()
if the size is not specified it is 400 x 400

Returns:
the size 400 x 400

windowStateChanged

public void windowStateChanged(WindowEvent event)
exits the application when the window closes and also terminates the server connections

Specified by:
windowStateChanged in interface WindowStateListener
See Also:
WindowStateListener.windowStateChanged(java.awt.event.WindowEvent)

getSessionName

public abstract String getSessionName()
gets the name of the session. The session name is used to determine instance of the game to join when connecting to the server.

Returns:
name of the sesson

getServerName

public abstract String getServerName()
gets the name of the server to connect to when joining a game. For applets, this must be the server from which it was downloaded. Applications are not restricted in the network connections they can make, so they can actually connect to other servers.

Returns:
the name of the server

getHostname

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

Returns:
the name of the localhost on the network

getCanvas

public abstract AnimationCanvas getCanvas()
abstract method to return canvas


setLoadMessage

public void setLoadMessage(String message)
sets a custom loading message

Parameters:
message - the text for the JLabel

begin

public abstract void begin()
starts the game. This method blocks until the game is connected.


getHash

public String getHash()
hashes the compiled source code in order to make sure that the only game which one can connect to is the exact same game.

Returns:
a relatively unique id based upon the compiled source

init

public void init()
sets the frame visible

Overrides:
init in class Applet

startGame

public abstract void startGame()
abstract method, starts game


stop

public void stop()
sets the frame invisible and pauses the game

Overrides:
stop in class Applet