Class EmissionApplet

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--BaseApplet
                                |
                                +--BaseApplet2
                                      |
                                      +--EmissionApplet
Direct Known Subclasses:
FeedbackApplet

public class EmissionApplet
extends BaseApplet2
implements java.lang.Runnable

Displays an animated diagram to illustrate absorption, emission (spontaneous and stimulated) and pumping.

See Also:
Serialized Form

Inner Class Summary
 class EmissionApplet.Electron
          Models an electron
 class EmissionApplet.Photon
          Models a photon
 
Inner classes inherited from class BaseApplet2
BaseApplet2.FixedButton, BaseApplet2.FixedCheckbox, 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  double absorb
          Probability that a passing photon will be absorbed by a particular electron
protected  java.awt.TextField absorbField
           
protected  java.awt.Button destroy
           
protected  boolean destroyPhotons
          Indicates that on the next logic cycle, all photons should be culled
protected  double dt
          The rate of advancement of simulation time
protected  EmissionApplet.Electron[] electrons
          An array of all the electrons in the simulation
protected  double electronSpeed
          The ratio of electron speed to photon speed
protected  double emit
          Probability that a passing photon will trigger an emission from a particular electron
protected  java.awt.TextField emitField
           
protected  java.awt.Button exciteAll
           
protected  int excitedY
          The y coordinate at which excited electrons should be drawn
protected  java.awt.Button exciteNone
           
protected  double hGap
          The width (in simulation units) of the spacing between electrons
protected  int hMargin
           
protected  java.awt.TextField inversionField
           
protected  java.awt.Button invert
           
protected  double margin
          Proportion of the simulation reserved at the top and bottom for electrons.
protected  int normalY
          The y coordinate at which non-excited electrons should be drawn
protected  java.util.Vector photons
          A list of all the photons in the simulation
protected  double pump
          Average proportion of non-excited electrons which will be pumped to the upper energy level in the time it takes for a photon to pass through the simulation.
protected  java.awt.TextField pumpField
           
protected  double simH
          The width (in simulation units) of the simulation
protected  double simW
          The width (in simulation units) of the simulation
protected  int[] sinTable
          Cache of sine values
protected  double spont
          Average proportion of excited electrons which will spontaneously emit a photon in the time it takes for a photon to pass through the simulation.
protected  java.awt.TextField spontField
           
protected  java.lang.Thread thr
          The thread used to perform the work of the simulation
protected  int vMargin
           
protected  int waveDispLen
           
 
Fields inherited from class BaseApplet2
boxes, buttons, enablePrompt, fields, focus, panel, statusLabel, useSwing, 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
EmissionApplet()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent ae)
          Subclasses should at least provide an empty implementation of this method.
protected  void addFields()
          Adds the text fields to the GUI
 void buildSineTable(int len, int amp)
          Creates a table of sine values (for painting the photons as waves).
 double calcInversion()
          Measures the population inversion (the proportion of electrons at the upper energy level.
 void createElectrons()
          Part of initialisation; creates a row of electrons, with spacing determined by hGap.
protected  int cullPhotons()
          Removes from the list any photons which have left the simulation.
 void destroyPhotons()
          Causes all photons in the simulation to be destroyed
 void doPaint(java.awt.Graphics g)
          Called by forcePaint() to actually perform the painting.
protected  EmissionApplet.Electron findElectron(double left, double right)
          Finds the first electron within a specified interval.
 void init()
          Performs extra initialisation, including adding a panel to the bottom of the applet.
 void invert()
          Applys the selected inversion to the electrons.
 void killAnim()
          Requests that the currently running simulation should stop at the next opportunity.
protected  void paintElectrons(java.awt.Graphics g, double xscl, double yscl)
          Paints all the electrons in the simulation.
protected  void paintPhotons(java.awt.Graphics g, double xscl, double yscl)
          Paints all the photons in the simulation.
protected  void paintWave(java.awt.Graphics g, int x, int y, int amp, double wavelength, int phase)
          Paints a sine wave to represent a photon.
 void run()
          Performs the work of the simulation: an update/repaint loop.
 void setAllExcited(boolean b)
          Sets all the electrons to either the upper or lower energy level.
 int sin(int x)
          Looks up the sin value to use for a particular x.
 void spawnPhoton()
          Creates a new photon at the "start" end of the simulation, with random vertical position (of no real consequence), and random phase.
 void start()
          Applets should use this method to perform any final initialisation necessary to "activate" the applet
 void startAnim()
          Requests that the simulation be started.
 void stop()
          When this method is called, the applet should cease any user interaction.
 void updateElectrons(double dt)
          Calls the update() method of every electron, thus advancing them through the specified time interval.
 void updateInput()
          Reads in (and validates) input from the text fields.
 void updatePhotons(double dt)
          Calls the update() method of every photon, thus advancing them through the specified time interval.
 
Methods inherited from class BaseApplet2
add, add, addButton, addCheckbox, addField, addField, addField, addListeners, focusGained, focusLost, getDouble, getGraphHeight, getInt, lockControls, makeButton, makePanel, paintDashedLineH, paintDashedLineV, register, removeListeners, setComponentsEnabled, setLayout, setPromptEnabled, textValueChanged, toString, unlockControls
 
Methods inherited from class BaseApplet
changeFont, 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

destroyPhotons

protected boolean destroyPhotons
Indicates that on the next logic cycle, all photons should be culled

absorb

protected double absorb
Probability that a passing photon will be absorbed by a particular electron

emit

protected double emit
Probability that a passing photon will trigger an emission from a particular electron

spont

protected double spont
Average proportion of excited electrons which will spontaneously emit a photon in the time it takes for a photon to pass through the simulation.

pump

protected double pump
Average proportion of non-excited electrons which will be pumped to the upper energy level in the time it takes for a photon to pass through the simulation.

thr

protected java.lang.Thread thr
The thread used to perform the work of the simulation

photons

protected java.util.Vector photons
A list of all the photons in the simulation

electrons

protected EmissionApplet.Electron[] electrons
An array of all the electrons in the simulation

simW

protected double simW
The width (in simulation units) of the simulation

simH

protected double simH
The width (in simulation units) of the simulation

hGap

protected double hGap
The width (in simulation units) of the spacing between electrons

dt

protected double dt
The rate of advancement of simulation time

electronSpeed

protected double electronSpeed
The ratio of electron speed to photon speed

margin

protected double margin
Proportion of the simulation reserved at the top and bottom for electrons. No photons will be created in those regions.

excitedY

protected int excitedY
The y coordinate at which excited electrons should be drawn

normalY

protected int normalY
The y coordinate at which non-excited electrons should be drawn

waveDispLen

protected int waveDispLen

hMargin

protected int hMargin

vMargin

protected int vMargin

sinTable

protected int[] sinTable
Cache of sine values

absorbField

protected java.awt.TextField absorbField

emitField

protected java.awt.TextField emitField

spontField

protected java.awt.TextField spontField

inversionField

protected java.awt.TextField inversionField

pumpField

protected java.awt.TextField pumpField

exciteAll

protected java.awt.Button exciteAll

exciteNone

protected java.awt.Button exciteNone

invert

protected java.awt.Button invert

destroy

protected java.awt.Button destroy
Constructor Detail

EmissionApplet

public EmissionApplet()
Method Detail

init

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

addFields

protected void addFields()
Adds the text fields to the GUI

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 BaseApplet2

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 BaseApplet2

doPaint

public void doPaint(java.awt.Graphics g)
Description copied from class: BaseApplet
Called by forcePaint() to actually perform the painting. Subclasses should implement this method as if it were the standard paint() method; buffering will then take place transparently.
Overrides:
doPaint in class BaseApplet
Tags copied from class: BaseApplet
Parameters:
g - The Graphics object on which to paint

paintPhotons

protected void paintPhotons(java.awt.Graphics g,
                            double xscl,
                            double yscl)
Paints all the photons in the simulation.
Parameters:
g - The Graphics surface on which to paint
xscl - Multiplier to convert simulation x coordinates to screen coordinates
yscl - Multiplier to convert simulation y coordinates to screen coordinates

paintElectrons

protected void paintElectrons(java.awt.Graphics g,
                              double xscl,
                              double yscl)
Paints all the electrons in the simulation.
Parameters:
g - The Graphics surface on which to paint
xscl - Multiplier to convert simulation x coordinates to screen coordinates
yscl - Multiplier to convert simulation y coordinates to screen coordinates

updateInput

public void updateInput()
Reads in (and validates) input from the text fields.
Throws:
java.lang.IllegalArgumentException - if any input fields are invalid

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent ae)
Description copied from class: BaseApplet
Subclasses should at least provide an empty implementation of this method.
Overrides:
actionPerformed in class BaseApplet

createElectrons

public void createElectrons()
Part of initialisation; creates a row of electrons, with spacing determined by hGap. Any prior existing electrons will be lost; all newly created electrons will be at the lower energy level.

updatePhotons

public void updatePhotons(double dt)
Calls the update() method of every photon, thus advancing them through the specified time interval. If there are currently no photons in the simulation, spawnPhoton() will be called to create one.

updateElectrons

public void updateElectrons(double dt)
Calls the update() method of every electron, thus advancing them through the specified time interval.

cullPhotons

protected int cullPhotons()
Removes from the list any photons which have left the simulation.
Returns:
The number of photons leaving

spawnPhoton

public void spawnPhoton()
Creates a new photon at the "start" end of the simulation, with random vertical position (of no real consequence), and random phase.

run

public void run()
Performs the work of the simulation: an update/repaint loop.
Specified by:
run in interface java.lang.Runnable

startAnim

public void startAnim()
Requests that the simulation be started. If a simulation is already in progress, this method will have no effect.

killAnim

public void killAnim()
Requests that the currently running simulation should stop at the next opportunity. If no simulation is running, this method will have no effect.

buildSineTable

public void buildSineTable(int len,
                           int amp)
Creates a table of sine values (for painting the photons as waves).
Parameters:
len - The wavelength, in pixels
amp - The amplitude, in pixels

sin

public int sin(int x)
Looks up the sin value to use for a particular x. Since this used the table built by buildSineTable(), it's much faster than Math.sin().

paintWave

protected void paintWave(java.awt.Graphics g,
                         int x,
                         int y,
                         int amp,
                         double wavelength,
                         int phase)
Paints a sine wave to represent a photon.
Parameters:
g - The Graphics surface on which to paint
x - The x coordinate of the leading end of the wave
y - The y coordinate of the leading end of the wave
amp - ignored; all waves now use the cached sine table
wavelength - used only to determine how much wave to draw.
phase - The phase shift for the wave

findElectron

protected EmissionApplet.Electron findElectron(double left,
                                               double right)
Finds the first electron within a specified interval. Used by photons to find an electron to interact with.

setAllExcited

public void setAllExcited(boolean b)
Sets all the electrons to either the upper or lower energy level.
Parameters:
b - true if all electrons should be excited, false if all electrins should be unexcited (bored?)

invert

public void invert()
Applys the selected inversion to the electrons. Electrons will be randomly distributed according to the inversion, with no regard to their previous energy level.

calcInversion

public double calcInversion()
Measures the population inversion (the proportion of electrons at the upper energy level.

destroyPhotons

public void destroyPhotons()
Causes all photons in the simulation to be destroyed