This action might not be possible to undo. Are you sure you want to continue?
The Greenfoot API consists of six classes:
World methods are available to the world.
Used to communicate with the Greenfoot environment itself. Provide information about the last mouse event.
For image presentation and manipulation. For controlling sound playback.
Actor methods are available to all actor subclasses.
World(int worldWidth, int worldHeight, int cellSize) void act() void addObject(Actor object, int x, int y) GreenfootImage getBackground() int getCellSize() Color getColorAt(int x, int y) int getHeight() List getObjects(Class cls) List getObjectsAt(int x, int y, Class cls) int getWidth() int numberOfObjects() void removeObject(Actor object) void removeObjects(Collection objects) void repaint() void setActOrder(Class... classes) void setBackground(GreenfootImage image) void setBackground(String filename) void setPaintOrder(Class... classes) void started() void stopped() Construct a new world. Act method for the world. Called once per act round. Add an Actor to the world. Return the world's background image. Return the size of a cell (in pixels). Return the color at the center of the cell. Return the height of the world (in number of cells). Get all the objects in the world. Return all objects at a given cell. Return the width of the world (in number of cells). Get the number of actors currently in the world. Remove an object from the world. Remove a list of objects from the world. Repaint the world. Set the act order of objects in the world. Set a background image for the world. Set a background image for the world from an image ﬁle. Set the paint order of objects in the world. Called by the Greenfoot system when execution has started. Called by the Greenfoot system when execution has stopped.
Greenfoot API version 2.0.2 is supported since Greenfoot version 2.0.1.
Create an image from an image ﬁle. Set the rotation of the object. Color background) void clear() Create a GreenfootImage from another GreenfootImage. Create an empty (transparent) image with the speciﬁed size. Return the world that this object lives in. Create an image with the given string drawn as text using the font size. boolean diagonal. (continued next page) . Return the y-coordinate of the object's current location. Set an image for this object from an image ﬁle. foreground color and background color. Assign a new location for this object. Class cls) protected Actor getOneIntersectingObject (Class cls) protected Actor getOneObjectAtOffset (int dx.0. int dy. Return all the objects that intersect this object. Class cls) Construct an Actor. Return an object that intersects this object. protected boolean intersects(Actor other) Check whether this object intersects another given object. Return all objects that intersect the given location (relative int dy. The act method is called by the Greenfoot framework to give objects a chance to perform some action. int size. Returns the image used to represent this Actor. int height) GreenfootImage(String filename) GreenfootImage(String string. Color foreground. Return the x-coordinate of the object's current location. Class GreenfootImage GreenfootImage(GreenfootImage image) GreenfootImage(int width. Return the current rotation of the object. protected List getObjectsInRange(int r. Clear the image. Return the neighbours to this object within a given distance.2 Class Actor Actor() void act() protected void addedToWorld(World world) GreenfootImage getImage() protected List getIntersectingObjects (Class cls) protected List getNeighbours (int distance.Greenfoot API Version 2. protected List getObjectsAtOffset(int dx. This method is called by the Greenfoot system when the object has been inserted into the world. Class cls) int getRotation() World getWorld() int getX() int getY() Return all objects within range 'r' around this object. Class cls) to this object's location). int y) void setRotation(int rotation) Set the image for this object to the speciﬁed image. void setImage(GreenfootImage image) void setImage(String filename) void setLocation(int x. Return one object that is located at the speciﬁed cell (relative to this objects location).
!y1) and (x2. between the points (x1. int yPoints. using the current font and color. Set the transparency of the image (range 0 to 255). int y2) void drawOval(int x. int x. Return the height of the image.!y2). int height) BufferedImage getAwtImage() Color getColor() Color getColorAt(int x. Mirror the image horizontally (ﬂip around the x-axis). int y. Fill an oval bounded by the speciﬁed rectangle with the current drawing color. void setFont(Font f) void setTransparency(int t) String toString() Set the current font.Greenfoot API Version 2. Return the width of the image. Get the current font. Rotates this image around the center. int height) void drawString(String string. int y1. Return the transparency of the image (range 0 to 255). Draw a line. int y. Mirror the image vertically (ﬂip around the y-axis). Return the current drawing color. Draws a closed polygon deﬁned by arrays of x and y coordinates. int y. Set the current drawing color. Return the color at the given pixel. int y) Font getFont() int getHeight() int getTransparency() int getWidth() void mirrorHorizontally() void mirrorVertically() void rotate(int degrees) void scale(int width. void setColorAt(int x. int y. using the current drawing color. int width.0. Draw an oval bounded by the speciﬁed rectangle with the current drawing color. int nPoints) void fillRect(int x. Fill a closed polygon deﬁned by arrays of x and y coordinates. int width. . int nPoints) void drawRect(int x. Returns the BufferedImage that backs this GreenfootImage. Draw the outline of the speciﬁed rectangle. Return a string representation of this image. int y) void fill() void fillOval(int x.2 Class GreenfootImage void drawImage(GreenfootImage image. int y. int height) void drawPolygon(int xPoints. int width. Fill the speciﬁed rectangle. int y) void drawLine(int x1. Fill the entire image with the current drawing color. int  yPoints. int x2. int height) void setColor(Color color) Draws the given Image onto this image. Color color) Sets the color at the given pixel to the given color. int width. int height) void fillPolygon(int xPoints. int x. Draw the text given by the speciﬁed string. Scales this image to a new size.
Class MouseInfo Actor getActor() int getButton() int getClickCount() int getX() int getY() String toString() Return the actor (if any) that the current mouse behaviour is related to. True the mouse has been pressed on the given object. Play this sound repeatedly in a loop. Returns a string representation of this sound containing the name of the ﬁle and whether it is currently playing or not. True if the sound is currently playing. True if a mouse drag has ended. Pauses the current sound if it is currently playing. Class GreenfootSound GreenfootSound(String filename) boolean isPlaying() void pause() void play() void playLoop() void stop() String toString() Create a new sound from the given ﬁle. Get the most recently pressed key since the last time this method was called. Return a random number between 0 (inclusive) and limit (exclusive). The current y position of the mouse cursor. The size of one time step is deﬁned by the speed slider. The number of the pressed or clicked button (if any). Run (or resume) the simulation. Set the speed of the simulation execution. Start playing this sound. True if the mouse has been clicked on the given object. The current x position of the mouse cursor. Delay execution by a number of time steps. Stop playing this sound if it is currently playing. Stop the simulation.2 Class Greenfoot Greenfoot() static void delay(int time) static String getKey() static MouseInfo getMouseInfo() static int getRandomNumber(int limit) static boolean isKeyDown(String keyName) static boolean mouseClicked(Object obj) static boolean mouseDragEnded(Object obj) static boolean mouseDragged(Object obj) static boolean mouseMoved(Object obj) static boolean mousePressed(Object obj) static void playSound(String soundFile) static void setSpeed(int speed) static void start() static void stop() Constructor. True if the mouse has been dragged on the given object. .0. Check whether a given key is currently pressed down. Return a string representation of this mouse event info. Play sound from a ﬁle. True if the mouse has been moved on the given object. Return an object with information about the mouse state.Greenfoot API Version 2. The number of mouse clicks of this mouse event.