Class BaseApplet2

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--BaseApplet
                                |
                                +--BaseApplet2
Direct Known Subclasses:
CCApplet, DCCApplet, Diffusion, EmissionApplet, FDApplet, HoleApplet, KP, Shoot, TimeDep, TransGraph

public abstract class BaseApplet2
extends BaseApplet
implements java.awt.event.TextListener, java.awt.event.FocusListener

Implements additional helper methods for managing a control panel along the bottom edge of the applet. Applets not wishing to use such a panel should extend BaseApplet instead.

Any buttons, textfields, or checkboxes added to the panel will be automatically registered to trigger ActionEvents on interaction with the user.

The add() and setLayout methods refer to this panel instead of the whole applet.

See Also:
Serialized Form

Inner Class Summary
(package private)  class BaseApplet2.FixedButton
          Mozilla-friendly Button
(package private)  class BaseApplet2.FixedCheckbox
          Mozilla-friendly Checkbox
 class BaseApplet2.GraphClickListener
           
 
Inner classes inherited from class BaseApplet
BaseApplet.MozillaWorkaround, BaseApplet.ResizeListener
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AWTTreeLock
 
Field Summary
protected  java.util.Vector boxes
           
protected  java.util.Vector buttons
           
protected  boolean enablePrompt
           
protected  java.util.Vector fields
           
protected  java.lang.Object focus
           
protected  java.awt.Panel panel
           
protected  java.awt.Label statusLabel
           
protected  boolean useSwing
           
static int V_MARGIN
           
 
Fields inherited from class BaseApplet
buffer, GRAPH_MARGIN, refresh, resizeListener, safetyLimit, useBuffer
 
Fields inherited from class java.applet.Applet
serialVersionUID, stub
 
Fields inherited from class java.awt.Panel
base, nameCounter, serialVersionUID
 
Fields inherited from class java.awt.Container
component, containerListener, containerSerializedDataVersion, dispatcher, layoutMgr, maxSize, ncomponents, serialVersionUID
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, assert, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, hasFocus, height, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, RIGHT_ALIGNMENT, serialVersionUID, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowListenerK, x, y
 
Constructor Summary
BaseApplet2()
           
 
Method Summary
 java.awt.Component add(java.awt.Component c)
          Adds a component to the control panel, and register()s the component.
 java.awt.Component add(java.awt.Component c, java.lang.String text)
          Adds a text label to the control panel, followed by the specified component, and register()s the component.
 java.awt.Button addButton(java.lang.String label)
          Creates a button, and adds it to the control panel.
 java.awt.Checkbox addCheckbox(java.lang.String label, boolean value)
          Creates a checkbox, and adds it to the control panel.
 java.awt.TextField addField(java.lang.String label, double value)
          Creates a text field, and adds it to the control panel.
 java.awt.TextField addField(java.lang.String label, int value)
          Creates a text field, and adds it to the control panel.
 java.awt.TextField addField(java.lang.String label, java.lang.String value)
          Creates a text field, and adds it to the control panel.
protected  void addListeners()
          Used internally to add listeners for all registered components
 void focusGained(java.awt.event.FocusEvent fe)
          Used to track focus to discern user-triggered changes from automatic changes.
 void focusLost(java.awt.event.FocusEvent fe)
          Used to track focus to discern user-triggered changes from automatic changes.
 double getDouble(java.awt.TextField tf)
          Parses a TextField into a double.
 int getGraphHeight()
          Returns the available space for graphs (or whatever the remainder of the display is to be used for).
 int getInt(java.awt.TextField tf)
          Parses a TextField into an int.
 void init()
          Performs extra initialisation, including adding a panel to the bottom of the applet.
protected  void lockControls()
          Disables all registed components
protected  java.awt.Component makeButton(java.lang.String label)
          Returns an instance of Button, of a subclass chosen at the discretion of the applet.
protected  java.awt.Container makePanel()
          Returns an instance of Container, of a subclass chosen at the discretion of the applet.
protected  void paintDashedLineH(java.awt.Graphics g, int x, int y, int x2, int dashLen)
          Helper method to display horizontal dashed lines
protected  void paintDashedLineV(java.awt.Graphics g, int x, int y, int y2, int dashLen)
          Helper method to display vertical dashed lines
protected  void register(java.awt.Component c)
          Registers a component with the applet.
protected  void removeListeners()
          Used internally to add listeners for all registered components
private static void setComponentsEnabled(java.util.Vector v, boolean b)
          Used internally to enable or disable a Vector of components.
 void setLayout(java.awt.LayoutManager lm)
          Sets the layout manager to use for the control panel.
 void setPromptEnabled(boolean b)
          Used to enable or disable user input prompting.
 void start()
          Applets should use this method to perform any final initialisation necessary to "activate" the applet
 void stop()
          When this method is called, the applet should cease any user interaction.
 void textValueChanged(java.awt.event.TextEvent te)
          Called when the contents of a text field have changed.
static java.lang.String toString(double d)
           
protected  void unlockControls()
          Enables all registed components
 
Methods inherited from class BaseApplet
actionPerformed, changeFont, doPaint, forcePaint, getAppletInfo, getParameterInfo, itemStateChanged, paint, refresh, update
 
Methods inherited from class java.applet.Applet
destroy, getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
, addNotify, constructComponentName
 
Methods inherited from class java.awt.Container
add, add, add, add, addContainerListener, addImpl, applyOrientation, countComponents, deliverEvent, dispatchEventImpl, dispatchEventToSelf, doLayout, eventEnabled, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getCursorTarget, getInsets, getLayout, getMaximumSize, getMinimumSize, getMouseEventTarget, getPreferredSize, getWindow, initIDs, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPrint, list, list, locate, minimumSize, nextFocus, paintComponents, paramString, postProcessKeyEvent, postsOldMouseEvents, preferredSize, preProcessKeyEvent, print, printComponents, printOneComponent, processContainerEvent, processEvent, proxyEnableEvents, proxyRequestFocus, readObject, remove, remove, removeAll, removeContainerListener, removeNotify, setCursor, setFocusOwner, setFont, transferFocus, updateCursor, validate, validateTree, writeObject
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getIntrinsicCursor, getLocation, getLocation, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getSize, getToolkit, getToolkitImpl, getTreeLock, getWidth, getWindowForObject, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, 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, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

focus

protected java.lang.Object focus

buttons

protected java.util.Vector buttons

fields

protected java.util.Vector fields

boxes

protected java.util.Vector boxes

panel

protected java.awt.Panel panel

statusLabel

protected java.awt.Label statusLabel

useSwing

protected boolean useSwing

enablePrompt

protected boolean enablePrompt

V_MARGIN

public static final int V_MARGIN
Constructor Detail

BaseApplet2

public BaseApplet2()
Method Detail

init

public void init()
Performs extra initialisation, including adding a panel to the bottom of the applet.
Overrides:
init in class BaseApplet

setLayout

public void setLayout(java.awt.LayoutManager lm)
Sets the layout manager to use for the control panel.
Overrides:
setLayout in class java.awt.Container
Parameters:
lm - The layout manager

makePanel

protected java.awt.Container makePanel()
Returns an instance of Container, of a subclass chosen at the discretion of the applet.

makeButton

protected java.awt.Component makeButton(java.lang.String label)
Returns an instance of Button, of a subclass chosen at the discretion of the applet.
Parameters:
label - The text which will appear on the button

addButton

public java.awt.Button addButton(java.lang.String label)
Creates a button, and adds it to the control panel.
Parameters:
label - The text to display on the button
Returns:
The button created

addField

public java.awt.TextField addField(java.lang.String label,
                                   java.lang.String value)
Creates a text field, and adds it to the control panel.
Parameters:
label - The initial text for the field
Returns:
The field created

addField

public java.awt.TextField addField(java.lang.String label,
                                   double value)
Creates a text field, and adds it to the control panel.
Parameters:
value - The initial value for the field
Returns:
The field created

addField

public java.awt.TextField addField(java.lang.String label,
                                   int value)
Creates a text field, and adds it to the control panel.
Parameters:
value - The initial value for the field
Returns:
The field created

addCheckbox

public java.awt.Checkbox addCheckbox(java.lang.String label,
                                     boolean value)
Creates a checkbox, and adds it to the control panel.
Parameters:
value - The initial value for the field
Returns:
The field created

register

protected void register(java.awt.Component c)
Registers a component with the applet. Any ItemEvent or ActionEvent generated by the component will now be passed on to the actionPerformed() method implemented by the subclass.
Parameters:
c - The component to register

add

public java.awt.Component add(java.awt.Component c)
Adds a component to the control panel, and register()s the component.
Overrides:
add in class java.awt.Container
Parameters:
c - The component to add

add

public java.awt.Component add(java.awt.Component c,
                              java.lang.String text)
Adds a text label to the control panel, followed by the specified component, and register()s the component.
Parameters:
c - The component to add
text - The label for the component

start

public void start()
Description copied from class: BaseApplet
Applets should use this method to perform any final initialisation necessary to "activate" the applet
Overrides:
start in class BaseApplet

stop

public void stop()
Description copied from class: BaseApplet
When this method is called, the applet should cease any user interaction. In particular, any threads explicitly started should be stopped, any external resources should be closed. This method should negate the action of start().
Overrides:
stop in class BaseApplet

addListeners

protected void addListeners()
Used internally to add listeners for all registered components

removeListeners

protected void removeListeners()
Used internally to add listeners for all registered components

getGraphHeight

public int getGraphHeight()
Returns the available space for graphs (or whatever the remainder of the display is to be used for).

getInt

public int getInt(java.awt.TextField tf)
Parses a TextField into an int.
Parameters:
tf - The field to parse
Returns:
The parsed value
Throws:
java.lang.NumberFormatException - If the parsing fails

getDouble

public double getDouble(java.awt.TextField tf)
Parses a TextField into a double.
Parameters:
tf - The field to parse
Returns:
The parsed value
Throws:
java.lang.NumberFormatException - If the parsing fails
java.lang.IllegalArgumentException - If the absolute value is less than 10e-8 (a measure to prevent unexpected underflow)

lockControls

protected void lockControls()
Disables all registed components

unlockControls

protected void unlockControls()
Enables all registed components

setComponentsEnabled

private static void setComponentsEnabled(java.util.Vector v,
                                         boolean b)
Used internally to enable or disable a Vector of components.
Parameters:
v - The vector of components
b - true if the components are to be enabled, else false

textValueChanged

public void textValueChanged(java.awt.event.TextEvent te)
Called when the contents of a text field have changed. If the user appears to have modified the value, the statusLabel will prompt the user to press return.
Specified by:
textValueChanged in interface java.awt.event.TextListener

focusGained

public void focusGained(java.awt.event.FocusEvent fe)
Used to track focus to discern user-triggered changes from automatic changes.
Specified by:
focusGained in interface java.awt.event.FocusListener

focusLost

public void focusLost(java.awt.event.FocusEvent fe)
Used to track focus to discern user-triggered changes from automatic changes.
Specified by:
focusLost in interface java.awt.event.FocusListener

setPromptEnabled

public void setPromptEnabled(boolean b)
Used to enable or disable user input prompting.

paintDashedLineH

protected void paintDashedLineH(java.awt.Graphics g,
                                int x,
                                int y,
                                int x2,
                                int dashLen)
Helper method to display horizontal dashed lines
Parameters:
g - The Graphics surface on which to paint
x - The x-coordinate of the start of the line
y - The y-coordinate of the start of the line
x2 - The x-coordinate of the end of the line
dashLen - The size of dash to use

paintDashedLineV

protected void paintDashedLineV(java.awt.Graphics g,
                                int x,
                                int y,
                                int y2,
                                int dashLen)
Helper method to display vertical dashed lines
Parameters:
g - The Graphics surface on which to paint
x - The x-coordinate of the start of the line
y - The y-coordinate of the start of the line
y2 - The y-coordinate of the end of the line
dashLen - The size of dash to use

toString

public static java.lang.String toString(double d)