optics
Class OpticsApplet

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--edu.davidson.tools.SApplet
                                |
                                +--optics.OpticsApplet
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class OpticsApplet
extends SApplet

This applet simulates an optics bench containing lenses, mirrors, and sources.

See Also:
Serialized Form

Fields inherited from class edu.davidson.tools.SApplet
clock, dataConnections, dataListeners, dataSources, lock
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
OpticsApplet()
           
 
Method Summary
 int addObject(java.lang.String name, java.lang.String parList)
          Create an object and add it to the Physlet.
 void clearAll()
          Clears all elements from bench and repaints
 java.lang.String getAppletInfo()
           
 double getFocalLength(int id)
          Get the element's focal length
 double getIndex(int id)
          Get the element's index of refraction.
 java.lang.String getParameter(java.lang.String key, java.lang.String def)
           
 java.lang.String[][] getParameterInfo()
           
 double getX(int id)
          Get the element's x position.
 double getY(int id)
          Get the element's y position.
 void init()
           
 void jbInit()
           
 boolean setAnimationSlave(int masterID, int slaveID)
          Force an object to follow another object on the screen.
 void setAutoRefresh(boolean ar)
          Repaint every time the system parameters are changed.
 void setBtnOff()
          Changes all the colors of the buttons to black
 boolean setConstraint(int id, int constraintID)
          Set a motion constraint on an object.
 void setDefault()
          Calls the following methods: setPixPerUnit(100), setInfo(false), setSize(.8), setDrag(false), setPropertyDrag(false), & setDirection(1)
 void setDirection(int d)
          Set the direction that sources added after will start in
 boolean setDisplayOffset(int id, int xOff, int yOff)
          Offset the object's position on the screen from its default drawing position.
 void setDrag(boolean d)
          Determines if elements added after value is set will be allowed to be dragged
 boolean setDragable(int id, boolean drag)
          Change the drag property of a wire or loop after it has been created.
 void setElementRGB(int r, int g, int b)
          Set the color of lenses and mirrors.
 void setInfo(boolean i)
          Determines if elements added after value will show information on screen including focal lengths and positions
 void setNull()
          Calls setBtnOff() and makes it so nothing is added when the mouse clicks the bench
 void setPixPerUnit(int ppu)
          Set the Pixels per Unit.
 void setPropertyDrag(boolean pd)
          Determines if elements added after value is set will be allowed to have their properties changed by dragging
 void setRayRGB(int r, int g, int b)
          Set the color of the source light rays.
 boolean setResizable(int id, boolean isResizable)
          Make an object resizable.
 boolean setRGB(int id, int r, int g, int b)
          Set the red, green, and blue color values for a wire or coil that has already been created.
 boolean setShowFocus(int id, boolean show)
          Change the showFocus property.
 void setSize(double s)
          Set the szie of the optic elements.
 void setUnDefault()
          Calls the following methods: setPixPerUnit(100), setInfo(true), setSize(.8), setDrag(true), setPropertyDrag(true), & setDirection(1)
 void start()
           
 
Methods inherited from class edu.davidson.tools.SApplet
addDataListener, addDataSource, cleanupDataConnections, clearAllData, clearData, deleteDataConnection, deleteDataConnections, destroy, forward, getClockID, getDataConnectionFromDL, getDataConnectionFromDS, getDataFromDS, getDataListener, getDataListener, getDataSource, getDataSource, getID, getRunningID, getSourceData, getSourceVariables, isAutoRefresh, isClockRunning, makeDataConnection, pause, removeDataListener, removeDataSource, reset, reverse, setClockContinous, setClockCycle, setClockOneShot, setClockTime, setConnectionBlock, setConnectionListener, setConnectionSmoothing, setConnectionSource, setConnectionStride, setDt, setFPS, setRunningID, setRunningID, setTimeContinuous, setTimeCycle, setTimeOneShot, startClock, stepClock, stepTime, stepTimeBack, stepTimeForward, stopClock, updateDataConnection, updateDataConnections, useMasterClock
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, removeNotify, setCursor, setFont, setLayout, update, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, disable, dispatchEvent, enable, enable, enableInputMethods, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OpticsApplet

public OpticsApplet()
Method Detail

getParameter

public java.lang.String getParameter(java.lang.String key,
                                     java.lang.String def)

init

public void init()
Overrides:
init in class java.applet.Applet

jbInit

public void jbInit()
            throws java.lang.Exception

start

public void start()
Overrides:
start in class java.applet.Applet

getAppletInfo

public java.lang.String getAppletInfo()
Overrides:
getAppletInfo in class java.applet.Applet

getParameterInfo

public java.lang.String[][] getParameterInfo()
Overrides:
getParameterInfo in class java.applet.Applet

setDisplayOffset

public boolean setDisplayOffset(int id,
                                int xOff,
                                int yOff)
Offset the object's position on the screen from its default drawing position.
Parameters:
id - The id of the object.
xoff - The x offset.
yoff - The y offset.
Returns:
True if successful.

clearAll

public void clearAll()
Clears all elements from bench and repaints

setDragable

public boolean setDragable(int id,
                           boolean drag)
Change the drag property of a wire or loop after it has been created. Use the id returned by the add methods to identify the object you wish to change.
Parameters:
id - the object identifier
drag - true if dragable
Returns:
true if successful

setShowFocus

public boolean setShowFocus(int id,
                            boolean show)
Change the showFocus property. The focus of lenses and mirrors will be drawn as a white dot on the axis.
Parameters:
id - the object identifier
show - true to show the focus
Returns:
true if successful

setConstraint

public boolean setConstraint(int id,
                             int constraintID)
Set a motion constraint on an object.
Parameters:
id - the ID of the object.
constraintID - the ID of the constraint.
Returns:
true if successful.

setDrag

public void setDrag(boolean d)
Determines if elements added after value is set will be allowed to be dragged
Parameters:
d - True or False

setAnimationSlave

public boolean setAnimationSlave(int masterID,
                                 int slaveID)
Force an object to follow another object on the screen.
Parameters:
masterID - The id of the master object.
slaveID - The id of the slave object.
Returns:
true if successful.

setResizable

public boolean setResizable(int id,
                            boolean isResizable)
Make an object resizable. A resizable object will usually change its physical properites. For example, a resizable lens will change its focal length.
Parameters:
id - the object identifier.
resizable - property
Returns:
true if successful.

setPropertyDrag

public void setPropertyDrag(boolean pd)
Determines if elements added after value is set will be allowed to have their properties changed by dragging
Parameters:
pd - True or False

setInfo

public void setInfo(boolean i)
Determines if elements added after value will show information on screen including focal lengths and positions
Parameters:
i - True or False

setElementRGB

public void setElementRGB(int r,
                          int g,
                          int b)
Set the color of lenses and mirrors. 0,0,0 will reset default.
Parameters:
r - 0g - 0b - 0

setRayRGB

public void setRayRGB(int r,
                      int g,
                      int b)
Set the color of the source light rays.
Parameters:
r - 0g - 0b - 0

setRGB

public boolean setRGB(int id,
                      int r,
                      int g,
                      int b)
Set the red, green, and blue color values for a wire or coil that has already been created. Color values must be in the range 0..255.
Parameters:
id - The id for the wire or loop.
r - red.
g - green.
b - blue.

setSize

public void setSize(double s)
Set the szie of the optic elements. Size=1 will make the height of the elements equal to the height of the applet.
Parameters:
s - Size in the range 0 to 1.0

setDirection

public void setDirection(int d)
Set the direction that sources added after will start in
Parameters:
d - d=1 or d=-1. d=1 is to the right. d=-1 is to the left

setPixPerUnit

public void setPixPerUnit(int ppu)
Set the Pixels per Unit.
Parameters:
ppu - 100 pixels per unit is as if on the screen 100 pixels represents 1 meter

setAutoRefresh

public void setAutoRefresh(boolean ar)
Repaint every time the system parameters are changed.
Overrides:
setAutoRefresh in class SApplet
Parameters:
ar - Automatic repaint?

setDefault

public void setDefault()
Calls the following methods: setPixPerUnit(100), setInfo(false), setSize(.8), setDrag(false), setPropertyDrag(false), & setDirection(1)
Overrides:
setDefault in class SApplet

setUnDefault

public void setUnDefault()
Calls the following methods: setPixPerUnit(100), setInfo(true), setSize(.8), setDrag(true), setPropertyDrag(true), & setDirection(1)

getFocalLength

public double getFocalLength(int id)
Get the element's focal length
Parameters:
id - The id of the element.

getX

public double getX(int id)
Get the element's x position.
Parameters:
id - The id of the element.

getY

public double getY(int id)
Get the element's y position.
Parameters:
id - The id of the element.

getIndex

public double getIndex(int id)
Get the element's index of refraction.
Parameters:
id - The id of the element.

addObject

public int addObject(java.lang.String name,
                     java.lang.String parList)
Create an object and add it to the Physlet. The first argument is the name of the object to be added and the second is a comma-delimited list of parameters. For example, a circle can be added a follows:

addObject ("circle", "x = 0, y = -1.0, r = 10");

Parameters:
name - the type of object to be created.
parList - a list of parameters to be set
Returns:
id that identifies the object.

setNull

public void setNull()
Calls setBtnOff() and makes it so nothing is added when the mouse clicks the bench

setBtnOff

public void setBtnOff()
Changes all the colors of the buttons to black

Copyright Wolfgang Christian

Visit the Davidson CollegePhyslets Page