waba.ui
Class MainWindow

java.lang.Object
  |
  +--waba.ui.Control
        |
        +--waba.ui.Container
              |
              +--waba.ui.Window
                    |
                    +--waba.ui.MainWindow
Direct Known Subclasses:
superwaba.ext.xplat.game.GameEngineMainWindow, Welcome

public class MainWindow
extends Window

MainWindow is the main window of a UI based application.

All SuperWaba programs with a user-interface must have one and only one main window.

Here is an example showing a basic application:

 public class MyProgram extends MainWindow
 {
    Edit edName;
    public void onStart()
    {
       ... initialization code ...
       add(new Label("Name:"), LEFT,TOP+2);
       add(edName = new Edit(""), AFTER,SAME-2);
    }
 }
 


Field Summary
static Font defaultFont
          Default font used in all controls created.
 
Fields inherited from class waba.ui.Window
beepIfOut, borderStyle, canDrag, eraseBackgroundNow, flicker, HIDE_STATE, highResPrepared, imgCovered, lastSwappedContainer, mainSwapContainer, menubar, needsPaint, NO_BORDER, RECT_BORDER, ROUND_BORDER, TAB_BORDER, TAB_ONLY_BORDER, title, titleFont, topMost, VK_BOTTOM, VK_HIDE, VK_TOP, zStack
 
Fields inherited from class waba.ui.Container
BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_SIMPLE, children, lastH, lastW, lastX, lastY, parentWindow, tail
 
Fields inherited from class waba.ui.Control
AFTER, appId, asContainer, asWindow, backColor, backDis, BEFORE, BOTTOM, CENTER, enabled, FILL, FIT, fm, fmH, focusLess, font, foreColor, foreDis, height, LEFT, parent, PREFERRED, RANGE, RIGHT, SAME, TOP, visible, width, x, x2, y, y2
 
Constructor Summary
MainWindow()
          Constructs a main window with no title and no border.
MainWindow(String title, byte style)
          Constructs a main window with the given title and border style.
 
Method Summary
 void _onTimerTick()
          Called by the VM to process timer interrupts.
 void _runThreads()
          Called by the VM to process threads.
 void addThread(Thread t, boolean highPriority)
          Add the given thread to the active list of threads.
protected  Timer addTimer(Control target, int millis)
          Adds a timer to a control.
 void appEnding()
          Called by the system so we can finish things correctly.
 void appStarting()
          Called by the VM when the application is starting.
 void exit(int exitCode)
          Notifies the application that it should stop executing and exit.
 String getCommandLine()
          Returns the command line passed by the application that called us in the Vm.exec method
 FontMetrics getFontMetrics(Font font)
          Returns the font metrics for a given font.
static MainWindow getMainWindow()
          Returns the MainWindow of the current application.
 void killThreads()
          Kill all running threads.
 void onExit()
          Called just before an application exits.
 void onStart()
          Called when an application starts.
 void removeThread(Thread t)
          Remove the given thread from the active list of threads.
 boolean removeTimer(Timer timer)
          Removes a timer.
 
Methods inherited from class waba.ui.Window
_doPaint, _doPaint, _postEvent, damageRect, destroyZStack, dontSaveBehind, getClientRect, getFocus, getOffScreen, getPreferredHeight, getPreferredWidth, getTopMost, isTopMost, isVisible, loadBehind, makeUnmovable, onClickedOutside, onPopup, onUnpop, paintTitle, popupBlockingModal, popupMenuBar, popupModal, postPopup, postUnpop, pumpEvents, saveBehind, setBorderStyle, setDoubleBuffer, setFocus, setMenuBar, setStatePosition, setTitle, setTitleFont, swap, unpop, validate
 
Methods inherited from class waba.ui.Container
add, add, add, broadcastEvent, findChild, getChildren, onColorsChanged, onPaint, paintChildren, remove, setEnabled
 
Methods inherited from class waba.ui.Control
addTimer, contains, createGraphics, getAbsoluteRect, getBackColor, getFont, getForeColor, getNext, getParent, getParentWindow, getPos, getRect, getSize, isDisplayed, isEnabled, onBoundsChanged, onEvent, onFontChanged, onWindowPaintFinished, postEvent, repaint, repaintNow, requestFocus, setBackColor, setBackForeColors, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setVisible
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, toString, wait, wait
 

Field Detail

defaultFont

public static Font defaultFont
Default font used in all controls created. To change the default font, assign it to this member in the MainWindow constructor.
Constructor Detail

MainWindow

public MainWindow()
Constructs a main window with no title and no border.

MainWindow

public MainWindow(String title,
                  byte style)
Constructs a main window with the given title and border style.
Since:
SuperWaba2.0b4
Method Detail

exit

public final void exit(int exitCode)
Notifies the application that it should stop executing and exit. It will exit after executing any pending events. If the underlying system supports it, the exitCode passed is returned to the program that started the app. Note: in PalmOS and in AppletViewer/Browser the exitCode is useless. If you want your code to be called when the VM exits, extend the onExit method.

getMainWindow

public static MainWindow getMainWindow()
Returns the MainWindow of the current application.

getFontMetrics

public FontMetrics getFontMetrics(Font font)
Returns the font metrics for a given font.
Overrides:
getFontMetrics in class Control

addTimer

protected Timer addTimer(Control target,
                         int millis)
Adds a timer to a control. This method is protected, the public method to add a timer to a control is the addTimer() method in the Control class.

removeTimer

public boolean removeTimer(Timer timer)
Removes a timer. This method returns true if the timer was found and removed and false if the given timer could not be found.
Overrides:
removeTimer in class Control

appStarting

public final void appStarting()
Called by the VM when the application is starting. Calls onStart. Never call this method directly; this method is not private to prevent the compiler from removing it during optimization.

appEnding

public final void appEnding()
Called by the system so we can finish things correctly. Never call this method directly; this method is not private to prevent the compiler from removing it during optimization.

onExit

public void onExit()
Called just before an application exits. When this is called, all threads are already killed.

onStart

public void onStart()
Called when an application starts. Initialization code is usually either placed in this method or simply in the app's constructor. This method is called just after the app's constructor is called.
Overrides:
onStart in class Container

_onTimerTick

public void _onTimerTick()
Called by the VM to process timer interrupts. This method is not private to prevent the compiler from removing it during optimization.

getCommandLine

public String getCommandLine()
Returns the command line passed by the application that called us in the Vm.exec method

addThread

public void addThread(Thread t,
                      boolean highPriority)
Add the given thread to the active list of threads. Note that a thread cannot be added twice; you must first remove it by calling removeThread.
Parameters:
t - the thread to be enqueued
highPriority - High priority threads (when parameter is true) are run all at once each time the MainWindow._runThreads method is called by the VM; low priority threads (when parameter is false) are run sequencially one at a time in each call of _runThreads by the VM. Making too much high priority threads isnt a good choice because it blocks normal events. After each call of MainWindow.runThreads, the VM dispatch the normal events.

removeThread

public void removeThread(Thread t)
Remove the given thread from the active list of threads. Calls the stopped method of the thread.

_runThreads

public void _runThreads()
Called by the VM to process threads. This method is not private to prevent the compiler from removing it during optimization.

killThreads

public void killThreads()
Kill all running threads. This method is for internal use only