Class 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
See Also:
  • 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 world
      h - the height for the world
  • Method Details

    • 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