Class TimerBean

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--TimerBean
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.lang.Runnable, java.io.Serializable

public class TimerBean
extends java.applet.Applet
implements java.lang.Runnable, java.io.Serializable

This Java Bean allows the user to visually display a "timer" or clock that increments to a specified time and then stops. When the specified time is reached (timeOut) the bean visually displays "TIME OUT". Also the bean gives ways to Start, Stop, Reset the timer and receive notifications of the user's actions.

Since:
08/16/2003
See Also:
Serialized Form

Inner classes inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Inner classes inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
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
TimerBean()
           
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          This method adds a listener to the TimerBean (bean).
 java.awt.Dimension getMinimumSize()
          This method defines the minimum size that the physical Applet can be.
 java.lang.String getTimeOut()
          This method returns the current value of the timeOut value.
 void init()
          The init method loads all the timer images that are needed in the bean.
 void paint(java.awt.Graphics g)
          The paint method paints the timer clock images on the Applet.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          This method removes a listener to the TimerBean.
 void resetTimer(java.awt.event.ActionEvent x)
          This method resets the timer to zero.
 void run()
          This thread increments the time every second until the timeOut value has been reached at which point the "Time Out" image is displayed.
 void setTimedOut(boolean status)
          This method sets the 'timedOut' flag to true if the time has timed out and false if it has not.
 void setTimeOut(java.lang.String s)
          This method sets the timeOut variable to a new value.
 void startTimer(java.awt.event.ActionEvent x)
          This method starts the timer.
 void stopTimer(java.awt.event.ActionEvent x)
          This method stops the timer.
 void updateStatus(java.lang.String s)
          This method is called whenever the status of the bean changes.
 
Methods inherited from class java.applet.Applet
destroy, getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getListeners, getMaximumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, 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, wait, wait, wait
 

Constructor Detail

TimerBean

public TimerBean()
Method Detail

init

public void init()
The init method loads all the timer images that are needed in the bean.

PRE: The init method assumes that all of the image files (*.gif) used in this project are located in the project directory.

POST: This method does nothing more than load in all the images and save them to the Image object array for future use in the program.

Overrides:
init in class java.applet.Applet

getMinimumSize

public java.awt.Dimension getMinimumSize()
This method defines the minimum size that the physical Applet can be.

PRE: None.

POST: This method does nothing more than return the Minimum Size Dimension of our Applet.

Overrides:
getMinimumSize in class java.awt.Container
Returns:
Dimensions of the minimum size applet.
Since:
08/16/2003

paint

public void paint(java.awt.Graphics g)
The paint method paints the timer clock images on the Applet. If by chance the timer has timed out then the "Time Out" image is displayed.

PRE: This method assumes that the parameter is valid and not equal to null.

POST: The main purpose of this method is to paint the current timer time or paint the "Time Out" image if time has expired. If by chance the Image Object array which was created in the "init" method is empty then a message notifying the user of the problem is printed.

Overrides:
paint in class java.awt.Container
Parameters:
g - Handle to the area on the Applet that will be painted.
Since:
08/16/2003

setTimedOut

public void setTimedOut(boolean status)
This method sets the 'timedOut' flag to true if the time has timed out and false if it has not.

PRE: This method assumes that the parameter is valid and not equal to null.

POST: This method does nothing more than set the "timedOut" variable equal to the parameter and return.

Parameters:
status - Status of the timer. Whether it has timed out or not.
Since:
08/16/2003

setTimeOut

public void setTimeOut(java.lang.String s)
This method sets the timeOut variable to a new value. An example of a valid timeOut value is "00:01:30" (1 minute 30 seconds).

PRE: This method assumes that the parameter is not equal to null. It is assumed that the string is in the following time format: "##:##:##" where # equals a positive numrical digit.

POST: This method does nothing more than set the "timeOut" String variable to the parameter and return.

Parameters:
s - New time that the timer will stop at.
Since:
08/16/2003

getTimeOut

public java.lang.String getTimeOut()
This method returns the current value of the timeOut value. The format that it returns is the following "##:##:##" where # = some number.

PRE: None.

POST: This method does nothing more than return the "timeOut" variable.

Returns:
returns timeOut value.
Since:
08/16/2003

run

public void run()
This thread increments the time every second until the timeOut value has been reached at which point the "Time Out" image is displayed.

PRE: This method assumes that the project has implemented "Runnable" and that the system that the project will be running on can handle threads.

POST: This method is the heart and soul of the project. This is were things get done. Anyways, if the thread/timer is not stopped and is enabled then the program gets the Graphics object and paints the current time of the timer or if it is timed out it paints the "Time Out" image. Next the method/thread sleeps for the time period of 1 second and then checks to see if the current timer time is equal to the timeOut value (the time the timer is supposed to stop at). If the timer time and the timeOut values are equal then the Timed Out flags are set and the "Time Out" image is painted. Otherwise the current timer time is incremented by 1. At this point the whole process is repeated.

Specified by:
run in interface java.lang.Runnable
Since:
08/16/2003

startTimer

public void startTimer(java.awt.event.ActionEvent x)
This method starts the timer. If the timer has timed out then the timer is reset and started or if the timer is stopped it will start the timer where it left off.

PRE: This method assumes that the ActionEvent parameter is not equal to null and that this method is called only when the user wants to start the timer.

POST: This method starts the timer thread and reset the counter if the "timedOut" flag is set. It also sets the "stopped" flag to false and notifies the "updateStatus" method that the timer has started.

Parameters:
x - Action from the user to start the timer.
Since:
08/16/2003

stopTimer

public void stopTimer(java.awt.event.ActionEvent x)
This method stops the timer.

PRE: This method assumes that it is called only if the user want the timer to be stopped or paused.

POST: This method first of all sets the "stopped" flag to true and notifies the "updateStatus" method that the timer has stopped. Then it gets the Graphic object and paints the current timer time or it paints the "Time Out" image if the timer has timed out.

Parameters:
x - Action from the user to stop the timer.
Since:
08/16/2003

resetTimer

public void resetTimer(java.awt.event.ActionEvent x)
This method resets the timer to zero.

PRE: This method assumes that it is called only when the user wants to reset the counter to zero.

POST: This method first of all sets the "stopped" flag to true and notifies the "updateStatus" method that the timer has been reset. Then the Graphics object it retrieved, the timer is reset to zero, and the initial time is painted on the GUI.

Parameters:
x - Action from the user to reset the timer.
Since:
08/16/2003

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
This method adds a listener to the TimerBean (bean). When an bean update occurs all the listed listeners are notified.

PRE: This method assumes that the parameter is not equal to null and that it represents a program that wants to listen for changes produced by this Timer Bean.

POST: This method does nothing more than add the listener to PropertyChangeSupport list.

Overrides:
addPropertyChangeListener in class java.awt.Component
Parameters:
listener - This is a handle to another object (bean) that wants to receive updates from the TimerBean.
Since:
08/16/2003

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
This method removes a listener to the TimerBean.

PRE: This method assumes that the parameter is not equal to null and that it represents a program that no longer wants to listen for changes produced by this Timer Bean.

POST: This method does nothing more than remove the listener from the PropertyChangeSupport list.

Overrides:
removePropertyChangeListener in class java.awt.Component
Parameters:
listener - Handle to the object (bean) that no longer wants to listen to TimerBean updates.
Since:
08/23/2003

updateStatus

public void updateStatus(java.lang.String s)
This method is called whenever the status of the bean changes. This method fires the property change, which in effect notifies all other objects (beans) listening.

PRE: This method assumes that the parameter is not equal to null.

POST: This method does nothing more than fire the "firePropertyChange" method letting all listeners of the Timer Bean know that the "status" property has changed. It also provides them with the current and old values.

Parameters:
s - String describing the new status of the bean.
Since:
08/16/2003