|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--javax.swing.JComponent
|
+--javax.swing.JPanel
|
+--ch.aplu.turtle.Playground
A Playground is the Turtle's home, i.e. the Turtle lives
and moves in the Playground.
ThePlayground is responsible for interpreting angle and position of the
Turtle and for choosing the correct turtle image and putting it on the right
spot of the Playground. This means: e.g. whenever you wish to switch the x- and y-axis, you
should do it in this class, and not in the Turtle class.
Remarks:
Playground needs a Window (e.g. Frame, Applet)
to be displayed. One possible solution for this problem is already given with the TurtleFrame
class, which implements the TurtleContainer interface. Applets are not yet supported.Turtle itself has only direct access to its Playground, but not to the
TurtleContainer.
| Nested Class Summary |
| Nested classes inherited from class javax.swing.JPanel |
JPanel.AccessibleJPanel |
| Nested classes inherited from class javax.swing.JComponent |
JComponent.AccessibleJComponent |
| Nested classes inherited from class java.awt.Container |
Container.AccessibleAWTContainer |
| Nested classes inherited from class java.awt.Component |
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
protected Color |
DEFAULT_BACKGROUND_COLOR
The default background color. |
| Fields inherited from class javax.swing.JComponent |
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
Playground(TurtleContainer rootpane)
Create a new Playground inside the given TurtleContainer and with
standard size (400 x 400 pixels). |
|
Playground(TurtleContainer rootpane,
Dimension size)
Create a new Playground inside the given TurtleContainer and
size. |
|
| Method Summary | |
void |
add(Turtle turtle)
Adds a new Turtle to the Playground. |
void |
blitToOffscreenBuffer()
Draws the whole canvas and turtle buffers into the offscreen buffer. |
void |
blitToOffscreenBuffer(Image buffer)
Draws an image into the offscreen buffer. |
void |
blitToOffscreenBuffer(Image buffer,
int x,
int y,
int w,
int h)
Draws part (a rectangle defined by the parameters) of an image into the offscreen buffer. |
void |
blitToOffscreenBuffer(int x,
int y,
int w,
int h)
Draws part of canvas and turtle buffers into the offscreen buffer, according to the rectangle definded by the parameters. |
void |
blitToOffscreenBuffer(Rectangle r)
Draws part of canvas and turtle buffers into the offscreen buffer, according to the given rectangle. |
void |
clear()
Clears the canvas (i.e. the buffer where all turtle lines are drawn). |
void |
clear(Graphics g)
Clears the buffer with the given Graphics. |
protected void |
clearClipTurtle(Turtle turtle)
This method is called when the given Turtle is in clip mode. |
protected void |
clearClipTurtle(Turtle turtle,
Image im)
Here the actual clearing of a Turtle in clip mode from the
given image is performed. |
void |
clearTurtle(Turtle turtle)
Removes the image of the given turtle from the turtle buffer. |
void |
clearTurtles()
Removes the image of all turtles from the turtle buffer. |
protected void |
clearWrapTurtle(Turtle turtle)
This method is called when the given Turtle is in wrap mode. |
protected void |
clearWrapTurtle(Turtle turtle,
Image im)
Here the actual clearing of a Turtle in wrap mode from the
given image is performed. |
int |
countTurtles()
Tells how many Turtles are now in this Playground. |
void |
fill(Turtle t)
Fills a region. |
protected Rectangle |
getBounds(Turtle turtle)
Calculates the bounds of the Turtles picture on the screen. |
Turtle |
getTurtle(int index)
Returns the Turtle at index index. |
boolean |
imageUpdate(Image img,
int infoflags,
int x,
int y,
int width,
int height)
|
protected void |
init(TurtleContainer rootpane,
Dimension size)
Initializes everything, e.g. creates a new vector (which holds the Turtles), the offscreen buffers, and sets the size and
background color. |
protected Point2D.Double |
internalToScreenCoords(double x,
double y)
Calculates the screen coordinates. |
void |
label(String text,
Turtle t)
Draws the text at the current position of the Turtle t.
|
void |
paintComponent()
Paints the Playground. |
void |
paintComponent(Graphics g)
Draws the canvas and turtle buffers. |
void |
paintTurtles()
Just paint all turtles. |
void |
paintTurtles(Turtle turtle)
Moves the given Turtle above all the others, then
paints all turtles. |
void |
remove(Turtle turtle)
Removes a Turtle from the Playground. |
Turtle |
toBottom(Turtle turtle)
Puts a Turtle beyond all others. |
Turtle |
toTop(Turtle turtle)
Puts a Turtle above all others. |
| Methods inherited from class javax.swing.JPanel |
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected Color DEFAULT_BACKGROUND_COLOR
| Constructor Detail |
public Playground(TurtleContainer rootpane)
TurtleContainer and with
standard size (400 x 400 pixels).
public Playground(TurtleContainer rootpane,
Dimension size)
TurtleContainer and
size.
| Method Detail |
protected void init(TurtleContainer rootpane,
Dimension size)
Turtles), the offscreen buffers, and sets the size and
background color.
DEFAULT_BACKGROUND_COLORpublic void add(Turtle turtle)
Turtle to the Playground.
public void remove(Turtle turtle)
Turtle from the Playground.
public int countTurtles()
Turtles are now in this Playground.
public Turtle getTurtle(int index)
Turtle at index index.
public void paintTurtles(Turtle turtle)
Turtle above all the others, then
paints all turtles.
toTop(ch.aplu.turtle.Turtle)public void paintTurtles()
public void fill(Turtle t)
Turtles actual position and
is bounded by any other color than the background color.Turtle is already standing on a colored
Pixel, nothing happens.
public void clear()
public void clear(Graphics g)
public void paintComponent()
public void paintComponent(Graphics g)
paintComponent in class JComponentpublic void blitToOffscreenBuffer()
public void blitToOffscreenBuffer(int x,
int y,
int w,
int h)
x - the rectangle's x-coordinatey - the rectangle's y-coordinatew - the rectangle's widthh - the rectangle's heightpublic void blitToOffscreenBuffer(Rectangle r)
public void blitToOffscreenBuffer(Image buffer)
buffer - The image to be drawn.
public void blitToOffscreenBuffer(Image buffer,
int x,
int y,
int w,
int h)
buffer - The image to be drawn.x - the rectangle's x-coordinatey - the rectangle's y-coordinatew - the rectangle's widthh - the rectangle's heightpublic void clearTurtles()
public void clearTurtle(Turtle turtle)
protected void clearWrapTurtle(Turtle turtle)
Turtle is in wrap mode.
Turtle.wrap()
protected void clearWrapTurtle(Turtle turtle,
Image im)
Turtle in wrap mode from the
given image is performed.
protected void clearClipTurtle(Turtle turtle)
Turtle is in clip mode.
Turtle.clip()
protected void clearClipTurtle(Turtle turtle,
Image im)
Turtle in clip mode from the
given image is performed.
public Turtle toTop(Turtle turtle)
public Turtle toBottom(Turtle turtle)
public boolean imageUpdate(Image img,
int infoflags,
int x,
int y,
int width,
int height)
imageUpdate in interface ImageObserverimageUpdate in class Component
protected Point2D.Double internalToScreenCoords(double x,
double y)
protected Rectangle getBounds(Turtle turtle)
Turtles picture on the screen.
public void label(String text,
Turtle t)
text at the current position of the Turtle t.
Drawing a text at some coordinates (x,y) we mean that the bottom left corner of
the text will be at these coordinates.
Font and colour are specified by the Turtle's Pen.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||