Class World
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,ModelDisplay
Class to represent a 2d world that can hold turtles and
display them
Copyright Georgia Institute of Technology 2004
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidMethod to add a model to this model displayervoidMethod to clear the background picturebooleancontainsTurtle(Turtle turtle) Method to check if this world contains the passed turtleMethod to get the graphics context for drawing onintMethod to get the height in pixelsMetod to get the last turtle in this worldMethod to get the background pictureMethod to get an iterator on the list of turtlesMethod to get the list of turtles in the worldintgetWidth()Method to get the width in pixelsvoidMethod that allows the model to notify the displayvoidMethod to paint this componentvoidMethod to remove the passed object from the worldvoidsetAutoRepaint(boolean value) Method to set the automatically repaint flagvoidsetPicture(Picture pict) Method to set the background picturevoidsetVisible(boolean value) Method to set the visibility of the worldtoString()Method that returns information about this world in the form of a stringMethods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, 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, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, updateUIMethods 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, transferFocusDownCycle, validate, validateTreeMethods 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, getAccessibleContext, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
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
-
-
Method Details
-
getGraphics
Method to get the graphics context for drawing on- Specified by:
getGraphicsin interfaceModelDisplay- Overrides:
getGraphicsin classJComponent- Returns:
- the graphics context of the background picture
-
clearBackground
public void clearBackground()Method to clear the background picture- Specified by:
clearBackgroundin interfaceModelDisplay
-
getPicture
-
setPicture
Method to set the background picture- Parameters:
pict- the background picture to use
-
paintComponent
Method to paint this component- Overrides:
paintComponentin classJComponent- Parameters:
g- the graphics context
-
getLastTurtle
Metod to get the last turtle in this world- Returns:
- the last turtle added to this world
-
addModel
Method to add a model to this model displayer- Specified by:
addModelin interfaceModelDisplay- Parameters:
model- the model object to add
-
containsTurtle
Method to check if this world contains the passed turtle- Returns:
- true if there else false
-
remove
Method to remove the passed object from the world- Specified by:
removein interfaceModelDisplay- Parameters:
model- the model object to remove
-
getWidth
public int getWidth()Method to get the width in pixels- Specified by:
getWidthin interfaceModelDisplay- Overrides:
getWidthin classJComponent- Returns:
- the width in pixels
-
getHeight
public int getHeight()Method to get the height in pixels- Specified by:
getHeightin interfaceModelDisplay- Overrides:
getHeightin classJComponent- Returns:
- the height in pixels
-
modelChanged
public void modelChanged()Method that allows the model to notify the display- Specified by:
modelChangedin interfaceModelDisplay
-
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:
setVisiblein classJComponent- Parameters:
value- a boolean value to say if should show or hide
-
getTurtleList
Method to get the list of turtles in the world- Returns:
- a list of turtles in the world
-
getTurtleIterator
Method to get an iterator on the list of turtles- Returns:
- an iterator for the list of turtles
-
toString
-