Class World
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
World
- All Implemented Interfaces:
- ImageObserver, MenuContainer, Serializable, ModelDisplay
public class World
- extends JComponent
- implements ModelDisplay
Class to represent a 2d world that can hold turtles and
display them
Copyright Georgia Institute of Technology 2004
- Author:
- Barb Ericson ericson@cc.gatech.edu
- See Also:
- Serialized Form
Constructor Summary |
World()
Constructor that takes no arguments |
World(boolean visibleFlag)
Constructor that takes a boolean to
say if this world should be visible
or not |
World(int w,
int h)
Constructor that takes a width and height for this
world |
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, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, 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, 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, getSize, 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, setSize, setSize, show, show, size, transferFocus, transferFocusUpCycle |
World
public World()
- Constructor that takes no arguments
World
public World(boolean visibleFlag)
- Constructor that takes a boolean to
say if this world should be visible
or not
- Parameters:
visibleFlag
- if true will be visible
else if false will not be visible
World
public World(int w,
int h)
- Constructor that takes a width and height for this
world
- Parameters:
w
- the width for the worldh
- the height for the world
getGraphics
public Graphics getGraphics()
- Method to get the graphics context for drawing on
- Specified by:
getGraphics
in interface ModelDisplay
- Overrides:
getGraphics
in class JComponent
- Returns:
- the graphics context of the background picture
clearBackground
public void clearBackground()
- Method to clear the background picture
- Specified by:
clearBackground
in interface ModelDisplay
getPicture
public Picture getPicture()
- Method to get the background picture
- Returns:
- the background picture
setPicture
public void setPicture(Picture pict)
- Method to set the background picture
- Parameters:
pict
- the background picture to use
paintComponent
public void paintComponent(Graphics g)
- Method to paint this component
- Overrides:
paintComponent
in class JComponent
- Parameters:
g
- the graphics context
getLastTurtle
public Turtle getLastTurtle()
- Metod to get the last turtle in this world
- Returns:
- the last turtle added to this world
addModel
public void addModel(Object model)
- Method to add a model to this model displayer
- Specified by:
addModel
in interface ModelDisplay
- Parameters:
model
- the model object to add
containsTurtle
public boolean containsTurtle(Turtle turtle)
- Method to check if this world contains the passed
turtle
- Returns:
- true if there else false
remove
public void remove(Object model)
- Method to remove the passed object from the world
- Specified by:
remove
in interface ModelDisplay
- Parameters:
model
- the model object to remove
getWidth
public int getWidth()
- Method to get the width in pixels
- Specified by:
getWidth
in interface ModelDisplay
- Overrides:
getWidth
in class JComponent
- Returns:
- the width in pixels
getHeight
public int getHeight()
- Method to get the height in pixels
- Specified by:
getHeight
in interface ModelDisplay
- Overrides:
getHeight
in class JComponent
- Returns:
- the height in pixels
modelChanged
public void modelChanged()
- Method that allows the model to notify the display
- Specified by:
modelChanged
in interface ModelDisplay
setAutoRepaint
public void setAutoRepaint(boolean value)
- Method to set the automatically repaint flag
- Parameters:
value
- if true will auto repaint
setVisible
public void setVisible(boolean value)
- Method to set the visibility of the world
- Overrides:
setVisible
in class JComponent
- Parameters:
value
- a boolean value to say if should show or hide
getTurtleList
public List getTurtleList()
- Method to get the list of turtles in the world
- Returns:
- a list of turtles in the world
getTurtleIterator
public Iterator getTurtleIterator()
- Method to get an iterator on the list of turtles
- Returns:
- an iterator for the list of turtles
toString
public String toString()
- Method that returns information about this world
in the form of a string
- Overrides:
toString
in class Component
- Returns:
- a string of information about this world