|
||||||||
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.
Field Summary |
Fields inherited from class javax.swing.JComponent |
TOOL_TIP_TEXT_KEY, 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.print.Printable |
NO_SUCH_PAGE, PAGE_EXISTS |
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,
java.awt.Dimension size)
Create a new Playground inside the given TurtleContainer and
size . |
Method Summary | |
void |
add(Turtle turtle)
Add a new Turtle to the Playground. |
void |
clear()
Clear the playground. |
void |
clearTurtle(Turtle turtle)
Remove the given turtle from the turtle buffer. |
void |
clearTurtles()
Remove all turtles from the turtle buffer. |
int |
countTurtles()
Tell current number of Turtle s in this Playground. |
void |
fill(Turtle t)
Fill a region. |
java.awt.Graphics2D |
getPrinterG2D()
Return the graphics context of the printer. |
java.awt.image.BufferedImage |
getTraceBuffer()
Return the image of the trace buffer. |
java.awt.Graphics2D |
getTraceG2D()
Return the graphics context of the trace buffer. |
Turtle |
getTurtle(int index)
Return the Turtle at index index . |
java.awt.image.BufferedImage |
getTurtleBuffer()
Return the image of the turtle buffer. |
java.awt.Graphics2D |
getTurtleG2D()
Returnt the graphics context of the turtle buffer. |
void |
label(java.lang.String text,
Turtle t)
Draw the text at the current position of the Turtle t .
|
void |
paintComponent()
Paint the Playground. |
void |
paintComponent(java.awt.Graphics g)
Draw the trace and turtle buffers. |
void |
paintTurtle(Turtle turtle)
Paint the given Turtle |
void |
paintTurtles()
Paint all turtles (calling paintComponent()) |
void |
paintTurtles(Turtle turtle)
Move the given Turtle above all the others, then
paints all turtles. |
int |
print(java.awt.Graphics g,
java.awt.print.PageFormat pf,
int pageIndex)
For internal use only. |
void |
remove(Turtle turtle)
Remove a Turtle from the Playground. |
void |
setAntiAliasing(boolean on)
Set antialiasing on or off for the turtle trace buffer This may result in an better trace quality. |
Turtle |
toBottom(Turtle turtle)
Put a Turtle below all others. |
java.awt.geom.Point2D.Double |
toScreenCoords(double x,
double y)
Calculate the screen coordinates of the given point coordinates. |
java.awt.geom.Point2D.Double |
toScreenCoords(java.awt.geom.Point2D.Double p)
Calculate the screen coordinates of the given point. |
Turtle |
toTop(Turtle turtle)
Puts a Turtle above all others. |
java.awt.geom.Point2D.Double |
toTurtleCoords(double x,
double y)
Calculate the turtle coordinates of the given screen coordinates. |
java.awt.geom.Point2D.Double |
toTurtleCoords(java.awt.geom.Point2D.Double p)
Calculate the turtle coordinates of the given screen point. |
Methods inherited from class javax.swing.JPanel |
getAccessibleContext, getUI, getUIClassID, setUI, updateUI |
Methods inherited from class javax.swing.JComponent |
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Playground(TurtleContainer rootpane)
TurtleContainer
and with
standard size (400 x 400 pixels).
public Playground(TurtleContainer rootpane, java.awt.Dimension size)
TurtleContainer
and
size
.
Method Detail |
public void add(Turtle turtle)
Turtle
to the Playground.
public void clear()
public void clearTurtle(Turtle turtle)
public void clearTurtles()
public int countTurtles()
Turtle
s in this Playground.
public void fill(Turtle t)
Turtle
s actual position and
is bounded by any other color than the background color.Turtle
is already standing on a colored
pixel, nothing happens.
public java.awt.Graphics2D getPrinterG2D()
public java.awt.image.BufferedImage getTraceBuffer()
public java.awt.Graphics2D getTraceG2D()
public Turtle getTurtle(int index)
Turtle
at index index
.
public java.awt.image.BufferedImage getTurtleBuffer()
public java.awt.Graphics2D getTurtleG2D()
public void label(java.lang.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.
public void paintComponent()
public void paintComponent(java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
public void paintTurtle(Turtle turtle)
Turtle
.
( no repaint() )
public void paintTurtles()
public void paintTurtles(Turtle turtle)
Turtle
above all the others, then
paints all turtles.
toTop(ch.aplu.turtle.Turtle)
public int print(java.awt.Graphics g, java.awt.print.PageFormat pf, int pageIndex)
print
in interface java.awt.print.Printable
public void remove(Turtle turtle)
Turtle
from the Playground.
public void setAntiAliasing(boolean on)
public Turtle toBottom(Turtle turtle)
public java.awt.geom.Point2D.Double toScreenCoords(double x, double y)
public java.awt.geom.Point2D.Double toScreenCoords(java.awt.geom.Point2D.Double p)
public Turtle toTop(Turtle turtle)
public java.awt.geom.Point2D.Double toTurtleCoords(double x, double y)
public java.awt.geom.Point2D.Double toTurtleCoords(java.awt.geom.Point2D.Double p)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |