Class BouncingBall

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by BouncingBall
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, javax.accessibility.Accessible

public class BouncingBall
extends java.applet.Applet
implements java.lang.Runnable

A class shows a ball moving inside a rectangular box

Since:
JDK 1.4
See Also:
Applet reference, Runnable reference, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.lang.Thread bouncingThread
          The thread that keeps the ball bouncing
protected  java.awt.Color color
          The ball color
protected  java.awt.Dimension d
          Size of the viewing area
protected  int delay
          If no parameter passed then we set interval between two consecutive frames
protected  int dx
          The distance that ball passed during the move
protected  int dy
          The distance that ball passed during the move
protected  java.awt.Image image
          Off-screen image
protected  java.awt.Graphics offscreen
          Off-screen graphics
protected  int radius
          The ball radius
protected  int x
          The ball coordinates of current position
protected  int y
          The ball coordinates of current position
 
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
BouncingBall()
           
 
Method Summary
 void init()
          The initialization of the object
 void paint(java.awt.Graphics g)
          Paints the box and the ball
 void run()
          Contains inifinite loop and periodically calls repaint method
 void start()
          Activates the applet
 void stop()
          Deactivates the applet
 void update(java.awt.Graphics g)
          Representation of the ball movement
 
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
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

color

protected java.awt.Color color
The ball color

See Also:
update(java.awt.Graphics)

radius

protected int radius
The ball radius

See Also:
init(), update(java.awt.Graphics)

x

protected int x
The ball coordinates of current position

See Also:
init(), update(java.awt.Graphics)

y

protected int y
The ball coordinates of current position

See Also:
init(), update(java.awt.Graphics)

dx

protected int dx
The distance that ball passed during the move

See Also:
update(java.awt.Graphics)

dy

protected int dy
The distance that ball passed during the move

See Also:
update(java.awt.Graphics)

image

protected java.awt.Image image
Off-screen image

See Also:
update(java.awt.Graphics)

offscreen

protected java.awt.Graphics offscreen
Off-screen graphics

See Also:
update(java.awt.Graphics)

d

protected java.awt.Dimension d
Size of the viewing area

See Also:
init(), update(java.awt.Graphics)

bouncingThread

protected java.lang.Thread bouncingThread
The thread that keeps the ball bouncing

See Also:
start(), stop(), run()

delay

protected int delay
If no parameter passed then we set interval between two consecutive frames

Constructor Detail

BouncingBall

public BouncingBall()
Method Detail

init

public void init()
The initialization of the object

Overrides:
init in class java.applet.Applet

update

public void update(java.awt.Graphics g)
Representation of the ball movement

Overrides:
update in class java.awt.Container

paint

public void paint(java.awt.Graphics g)
Paints the box and the ball

Overrides:
paint in class java.awt.Container
Parameters:
g - Graphics object to draw
See Also:
Graphics reference

start

public void start()
Activates the applet

Overrides:
start in class java.applet.Applet

stop

public void stop()
Deactivates the applet

Overrides:
stop in class java.applet.Applet

run

public void run()
Contains inifinite loop and periodically calls repaint method

Specified by:
run in interface java.lang.Runnable