|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgreenfoot.Greenfoot
public class Greenfoot
This utility class provides methods to control the simulation and interact with the system.
Part of the functionality provided by this class is the ability to retrieve keyboard input. The methods getKey() and isKeyDown() are used for this and they return/understand the following key names:
Constructor Summary | |
---|---|
Greenfoot()
|
Method Summary | |
---|---|
static void |
delay(int time)
Delay the current execution by a number of time steps. |
static java.lang.String |
getKey()
Get the most recently pressed key, since the last time this method was called. |
static int |
getMicLevel()
Get the microphone input level. |
static MouseInfo |
getMouseInfo()
Return a mouse info object with information about the state of the mouse. |
static int |
getRandomNumber(int limit)
Return a random number between 0 (inclusive) and limit (exclusive). |
static boolean |
isKeyDown(java.lang.String keyName)
Check whether a given key is currently pressed down. |
static boolean |
mouseClicked(java.lang.Object obj)
True if the mouse has been clicked (pressed and released) on the given object. |
static boolean |
mouseDragEnded(java.lang.Object obj)
True if a mouse drag has ended. |
static boolean |
mouseDragged(java.lang.Object obj)
True if the mouse has been dragged on the given object. |
static boolean |
mouseMoved(java.lang.Object obj)
True if the mouse has been moved on the given object. |
static boolean |
mousePressed(java.lang.Object obj)
True if the mouse has been pressed (changed from a non-pressed state to being pressed) on the given object. |
static void |
playSound(java.lang.String soundFile)
Play sound from a file. |
static void |
setSpeed(int speed)
Set the speed of the execution. |
static void |
setWorld(World world)
Sets the World to run to the one given. |
static void |
start()
Run (or resume) the execution. |
static void |
stop()
Pause the execution. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Greenfoot()
Method Detail |
---|
public static void setWorld(World world)
world
- The World to switch running to, cannot be null.public static java.lang.String getKey()
public static boolean isKeyDown(java.lang.String keyName)
keyName
- The name of the key to check
public static void delay(int time)
setSpeed(int)
public static void setSpeed(int speed)
speed
- The new speed. the value must be in the range (1..100)public static void stop()
public static void start()
public static int getRandomNumber(int limit)
public static void playSound(java.lang.String soundFile)
The file name may be an absolute path, a base name for a file located in the project directory or in the sounds directory of the project directory.
soundFile
- Typically the name of a file in the sounds directory in
the project directory.
java.lang.IllegalArgumentException
- If the sound can not be loaded.public static boolean mousePressed(java.lang.Object obj)
obj
- Typically one of Actor, World or null
public static boolean mouseClicked(java.lang.Object obj)
obj
- Typically one of Actor, World or null
public static boolean mouseDragged(java.lang.Object obj)
If the parameter is an Actor the method will only return true if the drag started on the given actor. If there are several actors at the same place, only the top most actor will receive the drag. If the parameter is a World then true will be returned if the drag action was started on the world background. If the parameter is null, then true will be returned for any drag action, independent of the target clicked on.
obj
- Typically one of Actor, World or null
public static boolean mouseDragEnded(java.lang.Object obj)
If the parameter is an Actor the method will only return true if the drag started on the given actor. If there are several actors at the same place, only the top most actor will receive the drag. If the parameter is a World then true will be returned if the drag action was started on the world background. If the parameter is null, then true will be returned for any drag action, independent of the target clicked on.
obj
- Typically one of Actor, World or null
public static boolean mouseMoved(java.lang.Object obj)
If the parameter is an Actor the method will only return true if the move is on the given actor. If there are several actors at the same place, only the top most actor will receive the move. If the parameter is a World then true will be returned if the move was on the world background. If the parameter is null, then true will be returned for any move, independent of the target under the move location.
obj
- Typically one of Actor, World or null
public static MouseInfo getMouseInfo()
public static int getMicLevel()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |