GTGE API

com.golden.gamedev
Class GameLoader

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 com.golden.gamedev.engine.graphics.AppletMode
                      extended by com.golden.gamedev.GameLoader
All Implemented Interfaces:
BaseGraphics, WindowListener, ImageObserver, MenuContainer, Serializable, Runnable, EventListener, Accessible

public class GameLoader
extends AppletMode
implements WindowListener, Runnable

GameLoader class is the class that manages Game class initialization.

GameLoader handles Game class graphics engine initialization, validating user Java version, and also catch any unexpected runtime error in Applet mode.

Example of how-to-use GameLoader in application mode :

    public class YourGame extends Game {

       public static void main(String[] args) {
          GameLoader game = new GameLoader();

          // init game with fullscreen mode, 640x480 screen resolution
          game.setup(new YourGame(), new Dimension(640,480), true);

          game.start();
       }

    }
 

In applet mode, GameLoader class need to be subclassed and override createAppletGame() method to return the actual game :

    public class YourGameApplet extends GameLoader {

       protected Game createAppletGame() {
          return new YourGame();
       }

    }
 
Then point the applet tag code to that GameLoader subclass :
(html page)
    <html>
    <head>
    </head>
    <body>

    <applet code="gamepackage.YourGameApplet.class"
            archive="yourgamearchive.jar,golden_x_x_x.jar"
            width=640 height=480>
    </applet>

    </body>
    </html>
 

See Also:
setup(Game, Dimension, boolean, boolean), start(), createAppletGame(), Serialized Form

Nested Class Summary
 
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  Game game
          The game (subclass of Game class) initialized by this GameLoader.
protected  BaseGraphics gfx
          Graphics engine loaded by this GameLoader.
static String JAVA_VERSION
          The installed Java Virtual Machine (JVM) version on player machine.
 String MINIMUM_VERSION
          The minimum Java version that the game known can be run properly.
 
Fields inherited from class com.golden.gamedev.engine.graphics.AppletMode
CONFIG, DEVICE
 
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
GameLoader()
          Constructs new GameLoader.
 
Method Summary
protected  Game createAppletGame()
          To play game in applet environment, GameLoader class need to be subclassed and this method need to be override to return the actual game object.
 Game getGame()
          Returns the game associated with this game loader or null if this game loader has not loaded any game.
 String getGraphicsDescription()
          Returns graphics engine description, for example: fullscreen, windowed, applet, fullscreen with bufferstrategy, etc.
 void paint(Graphics g)
          Draw essentials informations in applet game, for example : draw info when waiting the game to show up, or when the game is throwing an exception.
 void run()
          In applet environment the game have to be started in a thread, this is the thread implementation that actually launch the applet game.
 void setup(Game game, Dimension d, boolean fullscreen)
          Initializes graphics engine with specified size, mode, using bufferstrategy by default, and associates it with specified Game object.
 void setup(Game game, Dimension d, boolean fullscreen, boolean bufferstrategy)
          Initializes graphics engine with specified size, mode, bufferstrategy, and associates it with specified Game object.
 void start()
          Starts the game that have been loaded by this loader.
 void stop()
          Stops the game from running, to resume the game call start() again, please see note below.
protected  boolean validJavaVersion()
          Returns whether the Java version is passed the minimum Java version requirement or not.
 void windowActivated(WindowEvent e)
          Do nothing.
 void windowClosed(WindowEvent e)
          Do nothing.
 void windowClosing(WindowEvent e)
          If the user pressing frame close button while playing in WindowedMode or FullScreenMode, this method will receive the closing event.
 void windowDeactivated(WindowEvent e)
          Do nothing.
 void windowDeiconified(WindowEvent e)
          Do nothing.
 void windowIconified(WindowEvent e)
          Do nothing.
 void windowOpened(WindowEvent e)
          Do nothing.
 
Methods inherited from class com.golden.gamedev.engine.graphics.AppletMode
cleanup, destroy, flip, getBackBuffer, getComponent, getSize, getWindowIcon, getWindowTitle, setWindowIcon, setWindowTitle
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, init, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, 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, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, 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, 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

JAVA_VERSION

public static final String JAVA_VERSION
The installed Java Virtual Machine (JVM) version on player machine.


MINIMUM_VERSION

public String MINIMUM_VERSION
The minimum Java version that the game known can be run properly. The default is 1.4.

How to change the minimum Java version :

    GameLoader game = new GameLoader();
    game.MINIMUM_VERSION = "1.4.2";
    game.setup(....);
    game.start();
 
In applet mode, minimum version is specified in applet param 'MINIMUM' tag.
For example:
    <PARAM NAME="MINIMUM" VALUE="1.4.2">
 


gfx

protected BaseGraphics gfx
Graphics engine loaded by this GameLoader.


game

protected Game game
The game (subclass of Game class) initialized by this GameLoader.

Constructor Detail

GameLoader

public GameLoader()
Constructs new GameLoader.

See Also:
setup(Game, Dimension, boolean, boolean), start()
Method Detail

start

public void start()
Starts the game that have been loaded by this loader.

Overrides:
start in class AppletMode
See Also:
setup(Game, Dimension, boolean, boolean)

stop

public void stop()
Stops the game from running, to resume the game call start() again, please see note below.

By default this method is only called by browser in Applet Game.

Browser calls this method automatically when the web page contain the game is been replaced by another page and just before the applet is going to be destroyed.
The start() method is also automatically called by the browser each time the applet is being revisited.

Overrides:
stop in class Applet

run

public final void run()
In applet environment the game have to be started in a thread, this is the thread implementation that actually launch the applet game.

Specified by:
run in interface Runnable

createAppletGame

protected Game createAppletGame()
To play game in applet environment, GameLoader class need to be subclassed and this method need to be override to return the actual game object.

For example :

 public class YourGameApplet extends GameLoader {

    protected Game createAppletGame() {
       return new YourGame();
    }

 }
 


setup

public void setup(Game game,
                  Dimension d,
                  boolean fullscreen,
                  boolean bufferstrategy)
Initializes graphics engine with specified size, mode, bufferstrategy, and associates it with specified Game object.


setup

public void setup(Game game,
                  Dimension d,
                  boolean fullscreen)
Initializes graphics engine with specified size, mode, using bufferstrategy by default, and associates it with specified Game object.


getGame

public Game getGame()
Returns the game associated with this game loader or null if this game loader has not loaded any game.


paint

public void paint(Graphics g)
Draw essentials informations in applet game, for example : draw info when waiting the game to show up, or when the game is throwing an exception.

Overrides:
paint in class Container

validJavaVersion

protected boolean validJavaVersion()
Returns whether the Java version is passed the minimum Java version requirement or not.

Called this method before load the game to be sure the user machine has the minimum Java version to play the game.

See Also:
MINIMUM_VERSION

getGraphicsDescription

public String getGraphicsDescription()
Description copied from interface: BaseGraphics
Returns graphics engine description, for example: fullscreen, windowed, applet, fullscreen with bufferstrategy, etc.

Specified by:
getGraphicsDescription in interface BaseGraphics
Overrides:
getGraphicsDescription in class AppletMode

windowClosing

public void windowClosing(WindowEvent e)
If the user pressing frame close button while playing in WindowedMode or FullScreenMode, this method will receive the closing event.

In this implementation, pressing frame close button will instantly close any playing game by calling the game finish() method.

To avoid the game closed when frame close button is pressed, simply override this method or remove this listener from the graphics engine :

    GameLoader game = new GameLoader();
    game.setup(...);

    BaseGraphics gfx = game.getGame().bsGraphics;

    // only fullscreen and window mode the game is using frame
    if (gfx instanceof FullScreenMode) {
       // remove this listener
       ((FullScreenMode) gfx).getFrame().removeWindowListener(game);
    }

    if (gfx instanceof WindowedMode) {
       // remove this listener
       ((WindowedMode) gfx).getFrame().removeWindowListener(game);
    }

    game.start();
 

Specified by:
windowClosing in interface WindowListener

windowOpened

public void windowOpened(WindowEvent e)
Do nothing.

Specified by:
windowOpened in interface WindowListener

windowClosed

public void windowClosed(WindowEvent e)
Do nothing.

Specified by:
windowClosed in interface WindowListener

windowIconified

public void windowIconified(WindowEvent e)
Do nothing.

Specified by:
windowIconified in interface WindowListener

windowDeiconified

public void windowDeiconified(WindowEvent e)
Do nothing.

Specified by:
windowDeiconified in interface WindowListener

windowActivated

public void windowActivated(WindowEvent e)
Do nothing.

Specified by:
windowActivated in interface WindowListener

windowDeactivated

public void windowDeactivated(WindowEvent e)
Do nothing.

Specified by:
windowDeactivated in interface WindowListener

GTGE API

Copyright © 2003-2005 Golden T Studios. All rights reserved. Use is subject to license terms.
GoldenStudios.or.id