tipgame
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 tipgame.GameWindow
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.WindowStateListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.RootPaneContainer
Direct Known Subclasses:
FrameAdvancer

public abstract class GameWindow
extends javax.swing.JApplet
implements java.awt.event.ActionListener, java.awt.event.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
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
protected  javax.swing.JFrame frame
          frame for the GUI
protected  GameLoop gameLoop
          the GameLoop containing the animation canvas
protected  boolean hasFrame
          determines if the game should have its own frame
protected  HTMLDisplay help
          display for help information
(package private)  javax.swing.JButton helpPlay
          control buttons
(package private)  javax.swing.JButton mute
          control buttons
(package private)  javax.swing.JButton pause
          control buttons
(package private)  javax.swing.JButton quit
          control buttons
(package private)  javax.swing.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(java.awt.event.ActionEvent e)
          responds to control button presses
abstract  void disconnect()
          abstract method, disconnects
private  void exitGame()
          quits the application
abstract  AnimationCanvas getCanvas()
          abstract method to return canvas
private  javax.swing.JPanel getControlPanel()
          layout the bottom control panel
protected  java.awt.Dimension getDefaultSize()
          if the size is not specified it is 600 x 600
protected abstract  java.net.URL getHelpURL()
          this method must be overridden when extending the GameWindow.
 void init()
          sets the frame visible
private  void layoutComponents()
          position all components
private  void makeComponents()
          initialize all components
 void pauseToggle()
          toggles pause
 void runAsApplication()
          runs as an application
abstract  void setGameName(java.lang.String name)
          abstract method, sets the name of the game
abstract  void setNumberOfPlayers(int players)
          sets the number of players to wait for when starting a new game.
abstract  void setServerName(java.lang.String server)
          where this game's server resides
abstract  void setSessionName(java.lang.String session)
          sets the name of this particular instance of the game
 void setTitle(java.lang.String topTitle)
          Sets the title at the top of the JFrame
 void setUseFrame(boolean hasFrame)
          sets hasFrame to parameter hasFrame
abstract  void startGame()
          abstract method, starts game
 void stop()
          sets the frame invisible and pauses the game
 void toggleAudible()
          toggles the sound
 void windowStateChanged(java.awt.event.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 javax.swing.JFrame frame
frame for the GUI


pause

javax.swing.JButton pause
control buttons


quit

javax.swing.JButton quit
control buttons


helpPlay

javax.swing.JButton helpPlay
control buttons


mute

javax.swing.JButton mute
control buttons


gameLoop

protected GameLoop gameLoop
the GameLoop containing the animation canvas


title

javax.swing.JLabel title
title at the top of the frame


help

protected HTMLDisplay help
display for help information


hasFrame

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

Constructor Detail

GameWindow

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

Method Detail

setUseFrame

public void setUseFrame(boolean hasFrame)
sets hasFrame to parameter hasFrame

Parameters:
hasFrame -

runAsApplication

public void runAsApplication()
runs as an application


setGameName

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

Parameters:
name - name of game

setTitle

public void setTitle(java.lang.String topTitle)
Sets the title at the top of the JFrame

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(java.lang.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(java.lang.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(java.awt.event.ActionEvent e)
responds to control button presses

Specified by:
actionPerformed in interface java.awt.event.ActionListener

toggleAudible

public void toggleAudible()
toggles the sound


exitGame

private void exitGame()
quits the application


disconnect

public abstract void disconnect()
abstract method, disconnects


pauseToggle

public void pauseToggle()
toggles pause


getHelpURL

protected abstract java.net.URL getHelpURL()
this method must be overridden when extending the GameWindow. A single HTML help file should be placed in tipgame/util/html/your_package_name. This method should return the string:
your_package_name/your_help_file.html

Returns:
the name of the help file

getDefaultSize

protected java.awt.Dimension getDefaultSize()
if the size is not specified it is 600 x 600

Returns:
the size 600 x 600

windowStateChanged

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

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

makeComponents

private void makeComponents()
initialize all components


layoutComponents

private void layoutComponents()
position all components


getCanvas

public abstract AnimationCanvas getCanvas()
abstract method to return canvas


getControlPanel

private javax.swing.JPanel getControlPanel()
layout the bottom control panel


init

public void init()
sets the frame visible

Overrides:
init in class java.applet.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 java.applet.Applet