mdh.hephaestus2.gamelib
Class Application

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--mdh.hephaestus2.gamelib.Application
All Implemented Interfaces:
Accessible, ActionListener, EventListener, ImageObserver, KeyListener, MenuContainer, Serializable, WindowListener
Direct Known Subclasses:
Editor, Game

public class Application
extends Frame
implements ActionListener, KeyListener, WindowListener

GUI framework - holds a Screen and optional menu bar and status line (the latter two are created on demand), and provides a slew of basic services. Only one instance of Application may exist in a single program.

Author:
Copyright © 2002 by Mark Hughes <kamikaze@kuoi.asui.uidaho.edu>
See Also:
Serialized Form

Field Summary
static int ALT
           
static int CTRL
           
static int SHIFT
           
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
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
Application(String title)
           
Application(String title, ActionListener al)
           
 
Method Summary
 void actionPerformed(ActionEvent ae)
          Handles action events, including those generated by bound keys.
 void addHelpMenu(String title)
          Starts a new help menu.
 void addMenu(String title)
          Starts a new normal menu.
 void addMenuItem(String label, String cmd, int mods, int key)
          Adds a menu item with a hotkey to the current menu.
 void addMenuSeparator()
          Adds a menu separator to the current menu.
 int alert(double xalign, double yalign, String title, String text, String buttons, int def, int can, String iconfile)
          Shows an alert box, and returns the index (0-based) of the button pressed.
 HashMap audioCache()
          Returns the audio cache.
 void bindKey(String cmd, int mods, int key)
          Binds a key event to a given action command.
 void endMenus()
          Call at the end of all your menu creation to add the last menu and the menu bar.
 File fileDialog(String title, boolean open, String[] exts)
          Shows a custom file browser, and returns the File object selected, or null if the user hit cancel.
static Application getApplication()
           
 AudioClip getAudioClip(String filename)
          Returns a specified sound sample, stored in 'filename'.
 Image getImage(String filename)
          Returns a specified image, stored in 'filename' relative to docbase.
 String getStatus()
          Returns the text currently shown in the status line.
 boolean getVerifyQuit()
          Returns true if verifyQuit() should show a dialog box, false if it should just exit.
 HashMap imageCache()
          Returns the image cache.
 String input(double xalign, double yalign, String title, String prompt, String initialText, String iconfile)
          Shows a text input box, and returns the text entered, or null if the user hit Cancel.
 void keyPressed(KeyEvent ke)
          Handles keyboard input events - users should not call this method!
 void keyReleased(KeyEvent ke)
           
 void keyTyped(KeyEvent ke)
          Handles keyboard input events - users should not call this method!
 Button makeButton(String title, String cmd)
          Creates a button with a title and command, and forces sane colors.
 Choice makeChoice()
          Creates a drop-down choice with sane colors.
 IconList makeList(int len)
          Creates a scrolling list with sane colors.
 TextField makeTextField(String text)
           
 TextField makeTextField(String text, int minlen)
          Creates a text field with sane colors.
 Panel makeWhitePanel(Component comp)
          Creates a black-on-white panel with a single component maximized in it.
 int menu(double xalign, double yalign, String title, String text, ArrayList icons, IntStack keys, ArrayList options, boolean cancel, String iconfile)
          Shows a menu dialog, and returns the index (0-based) of the option selected, or null if the user hit Cancel.
 void playSound(String filename)
           
 void quit()
          Quits the program with exit code 0.
 void setScreen(Screen screen)
          Sets the Screen to use as the central component.
 void setVerifyQuit(boolean v)
          If 'v' is true, then when the window is closed or 'verifyQuit()' is called by other code, a dialog box will pop up asking if you're sure you want to quit.
 void show()
          Packs and shows the application.
 void showError(String s)
          Shows an error message in red in the status line.
 void showStatus(String s)
          Shows a line of text in the status line.
 void stopSounds()
          Stops all playing sounds.
 void verifyQuit()
          Pops up a dialog box to verify quitting.
 void windowActivated(WindowEvent e)
           
 void windowClosed(WindowEvent e)
           
 void windowClosing(WindowEvent e)
          Calls verifyQuit().
 void windowDeactivated(WindowEvent e)
           
 void windowDeiconified(WindowEvent e)
           
 void windowIconified(WindowEvent e)
           
 void windowOpened(WindowEvent e)
           
 
Methods inherited from class java.awt.Frame
addNotify, getAccessibleContext, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setIconImage, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

SHIFT

public static final int SHIFT
See Also:
Constant Field Values

CTRL

public static final int CTRL
See Also:
Constant Field Values

ALT

public static final int ALT
See Also:
Constant Field Values
Constructor Detail

Application

public Application(String title)

Application

public Application(String title,
                   ActionListener al)
Method Detail

getApplication

public static Application getApplication()

actionPerformed

public void actionPerformed(ActionEvent ae)
Handles action events, including those generated by bound keys. User applications should override this method!

Specified by:
actionPerformed in interface ActionListener

addHelpMenu

public final void addHelpMenu(String title)
Starts a new help menu.


addMenu

public final void addMenu(String title)
Starts a new normal menu.


addMenuItem

public final void addMenuItem(String label,
                              String cmd,
                              int mods,
                              int key)
Adds a menu item with a hotkey to the current menu.

Parameters:
label - label of the menu item.
cmd - action command.
key - modifiers for hotkeys - see KeyEvent.*_MASK.

addMenuSeparator

public final void addMenuSeparator()
Adds a menu separator to the current menu.


endMenus

public final void endMenus()
Call at the end of all your menu creation to add the last menu and the menu bar.


bindKey

public void bindKey(String cmd,
                    int mods,
                    int key)
Binds a key event to a given action command.


keyReleased

public void keyReleased(KeyEvent ke)
Specified by:
keyReleased in interface KeyListener

keyPressed

public void keyPressed(KeyEvent ke)
Handles keyboard input events - users should not call this method!

Specified by:
keyPressed in interface KeyListener
See Also:
KeyListener

keyTyped

public void keyTyped(KeyEvent ke)
Handles keyboard input events - users should not call this method!

Specified by:
keyTyped in interface KeyListener
See Also:
KeyListener

alert

public final int alert(double xalign,
                       double yalign,
                       String title,
                       String text,
                       String buttons,
                       int def,
                       int can,
                       String iconfile)
Shows an alert box, and returns the index (0-based) of the button pressed.

Parameters:
xalign - horizontal alignment of the box (0.5 = center, 0 = left, 1 = right)
yalign - vertical alignment of the box
title - Title of the dialog box
text - Text to display
buttons - List of button labels, delimited by "|", like "OK|Cancel"
def - Index of the default button (activated by pressing Enter); set 'def' to -1 to have no default.
can - Index of the cancel button (activated by pressing Escape); set 'def' to -1 to have no cancel.
iconfile - Filename of the icon image to display; set it to null to have no icon.

audioCache

public final HashMap audioCache()
Returns the audio cache.


fileDialog

public final File fileDialog(String title,
                             boolean open,
                             String[] exts)
Shows a custom file browser, and returns the File object selected, or null if the user hit cancel.

Parameters:
title - Title of the file browser dialog.
open - If true, the dialog is an open box and can only return existing files; if false, it is a save box, and can return new filenames.
exts - Array of permissible file extensions (must include the dot).

getAudioClip

public final AudioClip getAudioClip(String filename)
Returns a specified sound sample, stored in 'filename'.


getImage

public final Image getImage(String filename)
Returns a specified image, stored in 'filename' relative to docbase.


getStatus

public final String getStatus()
Returns the text currently shown in the status line.


getVerifyQuit

public final boolean getVerifyQuit()
Returns true if verifyQuit() should show a dialog box, false if it should just exit.


imageCache

public final HashMap imageCache()
Returns the image cache.


input

public final String input(double xalign,
                          double yalign,
                          String title,
                          String prompt,
                          String initialText,
                          String iconfile)
Shows a text input box, and returns the text entered, or null if the user hit Cancel.

Parameters:
xalign - horizontal alignment of the box (0.5 = center, 0 = left, 1 = right)
yalign - vertical alignment of the box
title - Title of the dialog box
prompt - Prompt to display in front of the input field
initialText - Initial text to put in the input field
iconfile - Filename of the icon image to display; set it to null to have no icon.

makeButton

public Button makeButton(String title,
                         String cmd)
Creates a button with a title and command, and forces sane colors.


makeChoice

public Choice makeChoice()
Creates a drop-down choice with sane colors.


makeWhitePanel

public Panel makeWhitePanel(Component comp)
Creates a black-on-white panel with a single component maximized in it.


makeList

public IconList makeList(int len)
Creates a scrolling list with sane colors.


makeTextField

public TextField makeTextField(String text)

makeTextField

public TextField makeTextField(String text,
                               int minlen)
Creates a text field with sane colors. The width of the field is 'minlen' or the length of the text, whichever is longer. Null text is treated as "".


menu

public int menu(double xalign,
                double yalign,
                String title,
                String text,
                ArrayList icons,
                IntStack keys,
                ArrayList options,
                boolean cancel,
                String iconfile)
Shows a menu dialog, and returns the index (0-based) of the option selected, or null if the user hit Cancel.

Parameters:
xalign - horizontal alignment of the box (0.5 = center, 0 = left, 1 = right)
yalign - vertical alignment of the box
title - Title of the dialog box
text - Text to display at the top of the dialog; set it to null to have no text.
icons - List of the icons for each option; set it to null to have no option icons. The values can be Images, or they can be Strings, in which case they are passed as filenames to getImage().
keys - List of the keys for each option; set it to null to use the default keys: A-Z for 0-25, then no key for further options.
options - List of the text for each option.
cancel - If true, there will be a Cancel button; if false, there will not.
iconfile - Filename of the icon image to display; set it to null to have no icon.

playSound

public void playSound(String filename)

quit

public void quit()
Quits the program with exit code 0.


setScreen

public void setScreen(Screen screen)
Sets the Screen to use as the central component.


setVerifyQuit

public final void setVerifyQuit(boolean v)
If 'v' is true, then when the window is closed or 'verifyQuit()' is called by other code, a dialog box will pop up asking if you're sure you want to quit.


show

public final void show()
Packs and shows the application.

Overrides:
show in class Window

showStatus

public final void showStatus(String s)
Shows a line of text in the status line. If the status line does not yet exist, it is created and added to the frame.


showError

public final void showError(String s)
Shows an error message in red in the status line.


stopSounds

public final void stopSounds()
Stops all playing sounds.


verifyQuit

public final void verifyQuit()
Pops up a dialog box to verify quitting. Call setVerifyQuit(false) if you don't need verification. The screen is paused while the dialog is up.


windowClosing

public final void windowClosing(WindowEvent e)
Calls verifyQuit().

Specified by:
windowClosing in interface WindowListener

windowDeiconified

public final void windowDeiconified(WindowEvent e)
Specified by:
windowDeiconified in interface WindowListener

windowIconified

public final void windowIconified(WindowEvent e)
Specified by:
windowIconified in interface WindowListener

windowActivated

public final void windowActivated(WindowEvent e)
Specified by:
windowActivated in interface WindowListener

windowDeactivated

public final void windowDeactivated(WindowEvent e)
Specified by:
windowDeactivated in interface WindowListener

windowClosed

public final void windowClosed(WindowEvent e)
Specified by:
windowClosed in interface WindowListener

windowOpened

public final void windowOpened(WindowEvent e)
Specified by:
windowOpened in interface WindowListener