|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
tipgame.AnimationCanvas
public class AnimationCanvas
This class is essentially a JPanel that contains Sprites
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
javax.swing.JComponent.AccessibleJComponent |
| 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 | |
|---|---|
private static java.awt.Color |
DEFAULT_BACKGROUND
the color to use when clearing the background |
private static java.awt.Dimension |
DEFAULT_SIZE
default size of canvas |
private int |
height
height of canvas |
private java.util.LinkedHashSet<Sprite> |
sprites
the ordered collection of Sprites. |
private Sprite[] |
waterMark
used for the transparent text at the bottom right |
private int |
width
width of the canvas |
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| 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 | |
|---|---|
AnimationCanvas()
constructs an empty canvas |
|
AnimationCanvas(java.awt.Dimension size)
constructs an empty canvas |
|
| Method Summary | |
|---|---|
void |
addBottom(Sprite sprite)
adds sprite to the bottom of the canvas |
void |
addSprite(Sprite sprite)
adds a Sprite to the canvas. |
private void |
clearBackground(java.awt.Graphics2D brush)
paints a rectangle in the default background color |
boolean |
containsSprite(Sprite sprite)
determines if the Sprite exists on the display |
Sprite[] |
getAllSprites()
gets a copy of the Sprite collection |
int |
getHeight()
returns height of the canvas |
java.awt.Dimension |
getMaximumSize()
returns maximum size |
java.awt.Dimension |
getMinimumSize()
returns minimum size |
java.awt.Dimension |
getPreferredSize()
returns the preferred size |
java.awt.Dimension |
getSize()
returns the size of the canvas |
int |
getWidth()
returns width of the canvas |
private void |
makeWaterMark()
makes the semi-transparent string sprites appearing at the lower right of the canvas. |
protected void |
paintComponent(java.awt.Graphics brush)
paints all of the Sprites in the center of the component |
void |
paintImmediately()
redraws the area which contains the Sprites |
private void |
paintSprites(java.awt.Graphics2D brush)
paints all of the Sprites |
void |
removeAllSprites()
clears the canvas of all Sprites |
void |
removeSprite(Sprite sprite)
removes the Sprite from the canvas. |
void |
setSize(java.awt.Dimension size)
sets size to size |
void |
setSize(int width,
int height)
sets the display size. |
void |
updateSprites(double timeInterval)
updates the cached array and removes all destoyed Sprites |
| Methods inherited from class javax.swing.JComponent |
|---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI |
| Methods inherited from class java.awt.Container |
|---|
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, 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 |
|---|
private java.util.LinkedHashSet<Sprite> sprites
private Sprite[] waterMark
private static final java.awt.Color DEFAULT_BACKGROUND
private static final java.awt.Dimension DEFAULT_SIZE
private int width
private int height
| Constructor Detail |
|---|
public AnimationCanvas()
public AnimationCanvas(java.awt.Dimension size)
| Method Detail |
|---|
private void makeWaterMark()
public void setSize(int width,
int height)
setSize in class java.awt.Componentsize - the size of the displaypublic void setSize(java.awt.Dimension size)
setSize in class java.awt.Componentsize - public void paintImmediately()
public int getWidth()
getWidth in class javax.swing.JComponentpublic int getHeight()
getHeight in class javax.swing.JComponentpublic void addSprite(Sprite sprite)
sprite - the Sprite to be addedpublic void removeSprite(Sprite sprite)
sprite - the Sprite to be removedpublic void removeAllSprites()
public boolean containsSprite(Sprite sprite)
sprite - the Sprite to check
public Sprite[] getAllSprites()
public void updateSprites(double timeInterval)
protected void paintComponent(java.awt.Graphics brush)
paintComponent in class javax.swing.JComponentbrush - the Graphics of the componentprivate void clearBackground(java.awt.Graphics2D brush)
brush - the Graphics of the componentprivate void paintSprites(java.awt.Graphics2D brush)
brush - the Graphics of the componentpublic void addBottom(Sprite sprite)
sprite - public java.awt.Dimension getSize()
getSize in class java.awt.Componentpublic java.awt.Dimension getPreferredSize()
getPreferredSize in class javax.swing.JComponentpublic java.awt.Dimension getMinimumSize()
getMinimumSize in class javax.swing.JComponentpublic java.awt.Dimension getMaximumSize()
getMaximumSize in class javax.swing.JComponent
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||