Class MainApplet

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--MainApplet
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.lang.Runnable, java.io.Serializable

public class MainApplet
extends java.applet.Applet
implements java.lang.Runnable, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

CLASS: MainApplet
PURPOSE: This class handle all the GUI action and this is also the main class for the applet
IMPORT: java.applet.Applet, java.awt.Graphics, java.awt.Image, java.awt.MediaTracker, java.awt.Color, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseEvent, FlyManager, FlyCreator
EXPORT: New Class|MainApplet
New Method| destroy, init, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, paint, run, setEyePos, update, drawFrog

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, java.awt.Component.AWTTreeLock
 
Field Summary
private  java.lang.Thread animation
          Thread for animation
private  java.awt.Graphics backBufferGraphics
          Graphic context associate with the back image buffer
private  java.awt.Image backBufferImage
          Back Image buffer for drawing
private  int drawTongue
          delay for drawing the tongue
private  int eye_x
          position of the frog's eye (x)
private  int eye_y
          position of the frog's eye (y)
private  int eyeCenterX
          position of the center of frog's eye (x)
private  int eyeCenterY
          position of the center of frog's eye (y)
private  int eyeEmotion
          For displaying eye emotion, happy, sad, netural
private  int eyeSize
          size of the frog's eye
private  int eyeXOffset
          x offset for drawing the frog's eye
private  int eyeYOffset
          y offset for drawing the frog's eye
private  FlyCreator fc
          FlyCreator for creating fly
private  java.awt.Image flyImage
          Fly image
private  FlyManager fm
          FlyManager for eating fly
private  java.awt.Image frogEatImage
          Frog image (eating)
private  int frogHeight
          Height of the frog image in pixel
private  java.awt.Image frogImage
          Frog image (still)
private  int frogWidth
          Width of the frog image in pixel
private  int frogY_pos
          position of the frog image
private  int height
          Display Height of the applet
private  int mouth_x
          position of the mouth(x)
private  int mouth_y
          position of the mouth(y)
private  long refreshRate
          rehresh rate in millisecond
private  int tongue_x
          destination of the tongue (x)
private  int tongue_y
          destination of the tongue (y)
private  int width
          Display Width of the applet
 
Fields inherited from class java.applet.Applet
accessibleContext, serialVersionUID, stub
 
Fields inherited from class java.awt.Panel
base, nameCounter
 
Fields inherited from class java.awt.Container
component, containerListener, containerSerializedDataVersion, dbg, dispatcher, layoutMgr, listeningBoundsChildren, listeningChildren, maxSize, ncomponents, printing, printingThreads
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, graphicsConfig, hasFocus, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, privateKey, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, visible, windowClosingException, windowListenerK, x, y
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
MainApplet()
           
 
Method Summary
 void destroy()
          
PRE: NONE
POST: Clean up the thread
private  void drawFrog(java.awt.Graphics g)
          
PRE: A valid Graphics object
POST: Draw the frog onto the Graphics object
 void init()
          
PRE: NONE
POST: Initialize all variables and start all the threads
 void mouseClicked(java.awt.event.MouseEvent e)
          
PRE: A valid MouseEvent object
POST: Nothing.
 void mouseDragged(java.awt.event.MouseEvent e)
          
PRE: A valid MouseEvent object
POST: Nothing.
 void mouseEntered(java.awt.event.MouseEvent e)
          
PRE: A valid MouseEvent object
POST: Nothing.
 void mouseExited(java.awt.event.MouseEvent e)
          
PRE: A valid MouseEvent object
POST: set the eye position to center
 void mouseMoved(java.awt.event.MouseEvent e)
          
PRE: A valid MouseEvent object
POST: Set eye position according to the mouse movement
 void mousePressed(java.awt.event.MouseEvent e)
          
PRE: A valid MouseEvent object
POST: try to eat the fly and set the animations
 void mouseReleased(java.awt.event.MouseEvent e)
          
PRE: A valid MouseEvent object
POST: Nothing.
 void paint(java.awt.Graphics g)
          
PRE: A valid Graphics object
POST: Paint all the objects
 void run()
          
PRE: NONE
POST: Refresh the screen in a timely manner and move the flies too
 void setEyePos(int x, int y)
          
PRE: NONE
POST: set the eye position so that it will stare at that point
 void update(java.awt.Graphics g)
          
PRE: A valid Graphics object
POST: Paint all the objects
 
Methods inherited from class java.applet.Applet
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, constructComponentName
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, adjustListeningChildren, applyOrientation, checkGD, countComponents, createChildHierarchyEvents, createHierarchyEvents, deliverEvent, dispatchEventImpl, dispatchEventToSelf, doLayout, eventEnabled, findComponentAt, findComponentAt, findComponentAt, getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMouseEventTarget, getPreferredSize, getWindow, initIDs, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPaint, lightweightPrint, list, list, locate, minimumSize, nextFocus, numListening, paintComponents, paintHeavyweightComponents, paramString, postProcessKeyEvent, postsOldMouseEvents, preferredSize, preProcessKeyEvent, print, printComponents, printHeavyweightComponents, processContainerEvent, processEvent, proxyEnableEvents, proxyRequestFocus, readObject, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusOwner, setFont, setLayout, transferFocus, validate, validateTree, writeObject
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkImage, checkImage, checkWindowClosingException, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAccessibleIndexInParent, getAccessibleStateSet, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen_NoTreeLock, 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, isRecursivelyVisible, 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, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, resetGC, 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, registerNatives, wait, wait, wait
 

Field Detail

frogImage

private java.awt.Image frogImage
Frog image (still)

frogEatImage

private java.awt.Image frogEatImage
Frog image (eating)

flyImage

private java.awt.Image flyImage
Fly image

refreshRate

private long refreshRate
rehresh rate in millisecond

animation

private java.lang.Thread animation
Thread for animation

fm

private FlyManager fm
FlyManager for eating fly

fc

private FlyCreator fc
FlyCreator for creating fly

width

private int width
Display Width of the applet

height

private int height
Display Height of the applet

frogHeight

private int frogHeight
Height of the frog image in pixel

frogWidth

private int frogWidth
Width of the frog image in pixel

frogY_pos

private int frogY_pos
position of the frog image

eye_y

private int eye_y
position of the frog's eye (y)

eye_x

private int eye_x
position of the frog's eye (x)

eyeCenterX

private int eyeCenterX
position of the center of frog's eye (x)

eyeCenterY

private int eyeCenterY
position of the center of frog's eye (y)

eyeSize

private int eyeSize
size of the frog's eye

eyeXOffset

private int eyeXOffset
x offset for drawing the frog's eye

eyeYOffset

private int eyeYOffset
y offset for drawing the frog's eye

drawTongue

private int drawTongue
delay for drawing the tongue

tongue_y

private int tongue_y
destination of the tongue (y)

tongue_x

private int tongue_x
destination of the tongue (x)

mouth_x

private int mouth_x
position of the mouth(x)

mouth_y

private int mouth_y
position of the mouth(y)

eyeEmotion

private int eyeEmotion
For displaying eye emotion, happy, sad, netural

backBufferImage

private java.awt.Image backBufferImage
Back Image buffer for drawing

backBufferGraphics

private java.awt.Graphics backBufferGraphics
Graphic context associate with the back image buffer
Constructor Detail

MainApplet

public MainApplet()
Method Detail

init

public void init()

PRE: NONE
POST: Initialize all variables and start all the threads
Overrides:
init in class java.applet.Applet

paint

public void paint(java.awt.Graphics g)

PRE: A valid Graphics object
POST: Paint all the objects
Overrides:
paint in class java.awt.Container

update

public void update(java.awt.Graphics g)

PRE: A valid Graphics object
POST: Paint all the objects
Overrides:
update in class java.awt.Container

drawFrog

private void drawFrog(java.awt.Graphics g)

PRE: A valid Graphics object
POST: Draw the frog onto the Graphics object

run

public void run()

PRE: NONE
POST: Refresh the screen in a timely manner and move the flies too
Specified by:
run in interface java.lang.Runnable

setEyePos

public void setEyePos(int x,
                      int y)

PRE: NONE
POST: set the eye position so that it will stare at that point

destroy

public void destroy()

PRE: NONE
POST: Clean up the thread
Overrides:
destroy in class java.applet.Applet

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)

PRE: A valid MouseEvent object
POST: set the eye position to center
Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)

PRE: A valid MouseEvent object
POST: Nothing. Require for the MouseMotionListener Interface
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)

PRE: A valid MouseEvent object
POST: Set eye position according to the mouse movement
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)

PRE: A valid MouseEvent object
POST: Nothing. Require for the MouseMotionListener Interface
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)

PRE: A valid MouseEvent object
POST: Nothing. Require for the MouseListener Interface
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)

PRE: A valid MouseEvent object
POST: try to eat the fly and set the animations
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)

PRE: A valid MouseEvent object
POST: Nothing. Require for the MouseListener Interface
Specified by:
mouseClicked in interface java.awt.event.MouseListener