ch.aplu.gidlet
Class Playground

java.lang.Object
  extended by javax.microedition.lcdui.Displayable
      extended by javax.microedition.lcdui.Canvas
          extended by ch.aplu.gidlet.Playground

public class Playground
extends javax.microedition.lcdui.Canvas

Graphics window of full screen width and height (client drawing area), exclusively used as canvas for the class Turtle.

A current graph position is used, that remembers the end position of the last drawing process and where new drawings start.

A soft button 'Exit' is shown. Hitting the corresponding key will call the Gidlet's doExit(). If you do not need this button, invoke removeExitButton().
If you implement your own CommandListener and call setCommandListener(), the internal CommandListener is disabled.

See Also:
Turtle

Field Summary
 
Fields inherited from class javax.microedition.lcdui.Canvas
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP
 
Constructor Summary
protected Playground(Turtle turtle, java.lang.String title, double range, int bgColor, int turtleColor, int penColor, int titleColor, boolean visible, boolean isShown)
           
 
Method Summary
protected  void _draw(int x, int y)
          Draws a line into trace buffer from current graph position to given pixel coordinates and sets the graph position to the endpoint.
protected  void _fillRectangle(int ulx, int uly, int lrx, int lry, int color)
          Draws a filled rectangle with given opposite corners in pixel coordinates into trace buffer using the given color.
protected  void _fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int color)
          Draws a filled triangle with given corners in pixel coordintates into trace buffer using the given color.
protected  int _getPosX()
          Returns pixel coordinate x of current graph position.
protected  int _getPosY()
          Returns pixel coordinate y of current graph position.
protected  boolean _image(java.lang.String imageUrl, int x, int y)
          Puts the PNG image into turtle buffer from given file url at given pixel coordinates (specifies upper left corner of image).
protected  int _imageHeight(java.lang.String imageUrl)
          Returns the height (vertical size) of the PNG image from the given url (in pixel coordinates).
protected  int _imageWidth(java.lang.String imageUrl)
          Returns the width (horizontal size) of the PNG image from the given url (in pixel coordinates).
protected  void _line(int x1, int y1, int x2, int y2)
          Draws a line with given pixel coordinates into trace buffer and sets the graph position to the endpoint.
protected  void _move(int x, int y)
          Sets the current graph position into trace buffer to given pixel coordinates (without drawing anything).
protected  void _rectangle(int ulx, int uly, int lrx, int lry)
          Draws a rectangle with given opposite corners in pixel coordinates into trace buffer.
protected  int _screenHeight()
          Returns height of screen in pixel coordinates.
protected  int _screenWidth()
          Returns width of screen in pixel coordinates.
protected  void _triangle(int x1, int y1, int x2, int y2, int x3, int y3)
          Draws a triangle with given corners in pixel coordintates.
protected  void addKeyListener(KeyListener keyListener)
          Registers an KeyListener to get a notification when a button is clicked.
protected  void addLabel(java.lang.String text, int x, int y, int index, int color)
          Shows the given text with given color left adjusted at given x, y pixel coordinate.
 void addOkButton()
          Adds an OK soft button with label "OK".
 void addOkButton(java.lang.String label)
          Adds an OK soft button with given label.
protected  void clear(boolean init)
          Clears the graphics buffers (fully paint with background color) and draws a surrounding white rectangle.
protected  void draw(double x, double y)
          Draws a line into trace buffer from current graph position to given window coordinates and sets the graph position to the endpoint.
protected  void drawLabels()
           
protected  void fillRectangle(double x1, double y1, double x2, double y2, int color)
          Draws a filled rectangle with given opposite corners in window coordinates using the given color.
protected  void fillTriangle(double x1, double y1, double x2, double y2, double x3, double y3, int color)
          Draws a filled triangle with given corners in window coordintates using the given color.
protected  double getAspectRatio()
          Returns the ratio of canvas height to width.
protected  double getPosX()
          Returns window coordinate x of current graph position.
protected  double getPosY()
          Returns window coordinate y of current graph position.
protected  javax.microedition.lcdui.Graphics getTraceBuffer()
          Returns the graphics turtle buffer.
protected  javax.microedition.lcdui.Image getTraceImage()
          Returns the trace image.
protected  javax.microedition.lcdui.Graphics getTurtleBuffer()
          Returns the graphics turtle buffer.
protected  javax.microedition.lcdui.Image getTurtleImage()
          Returns the turtle image.
protected  boolean image(java.lang.String imageUrl, double x, double y)
          Puts the PNG image into turtle buffer from given file url at given window coordinates (specifies upper left corner of image).
protected  double imageHeight(java.lang.String imageUrl)
          Returns the height (vertical size) of the PNG image from the given url (in window coordinates).
protected  double imageWidth(java.lang.String imageUrl)
          Returns the width (horizontal size) of the PNG image from the given url (in window coordinates).
protected  void init()
          Initializes Playground.
protected  void keyPressed(int keyCode)
          Used to get key events.
protected  void keyReleased(int keyCode)
          Used to get key events.
protected  void keyRepeated(int keyCode)
          Used to get key events.
protected  void line(double x1, double y1, double x2, double y2)
          Draws a line into trace buffer with given window coordinates into given buffer and sets the graph position to the endpoint.
protected  void move(double x, double y)
          Sets the current graph position in trace buffer to given window coordinates (without drawing anything).
protected  void paint(javax.microedition.lcdui.Graphics g)
          Used for rendering canvas.
protected  void rectangle(double x1, double y1, double x2, double y2)
          Draws a rectangle with given opposite corners in window coordinates.
 void removeExitButton()
          Removes Exit soft button.
protected  void removeKeyListener()
          Removes a registered KeyListener.
protected  void removeLabel(int index)
          Removes text with given index.
 void removeOkButton()
          Removes OK soft button.
protected  double screenHeight()
          Returns height of screen in window coordinates.
protected  int screenResolutionX()
          Returns number of pixels in horizontal direction.
protected  int screenResolutionY()
          Returns number of pixels in vertical direction.
protected  double screenWidth()
          Returns width of screen in window coordinates.
protected  int setTracePenColor(int color)
          Sets color of drawing pen in trace buffer.
 void show()
          Shows the form display if it is not yet visible or it was previously hidden by another display.
protected  void show(boolean wait)
          Shows the graphics display if it was previously hidden by another display or not yet displayed.
protected  int toPixelHeight(double windowHeight)
          Converts window coordinates increment to pixel coordinates increment (vertical).
protected  int toPixelWidth(double windowWidth)
          Converts window coordinates increment to pixel coordinates increment (horizontal).
protected  int toPixelX(double windowX)
          Converts window coordinates to pixel coordinates (horizontal).
protected  int toPixelY(double windowY)
          Converts window coordinates to pixel coordinates (vertical).
protected  double toWindowHeight(int pixelHeight)
          Converts pixel coordinates increment to window coordinates increment (vertical).
protected  double toWindowWidth(int pixelWidth)
          Converts pixel coordinates increment to window coordinates increment (horizontal).
protected  double toWindowX(int userX)
          Converts pixel coordinates to window coordinates (horizontal).
protected  double toWindowY(int userY)
          Converts pixel coordinates to window coordinates (vertical).
protected  void triangle(double x1, double y1, double x2, double y2, double x3, double y3)
          Draws a triangle with given corners in window coordintates.
protected  void window(double xmin, double xmax, double ymin, double ymax)
          Sets window coordinates.
 
Methods inherited from class javax.microedition.lcdui.Canvas
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, hideNotify, isDoubleBuffered, pointerDragged, pointerPressed, pointerReleased, repaint, repaint, serviceRepaints, setCommandListener, setFullScreenMode, showNotify, sizeChanged
 
Methods inherited from class javax.microedition.lcdui.Displayable
addCommand, getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setTicker, setTitle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Playground

protected Playground(Turtle turtle,
                     java.lang.String title,
                     double range,
                     int bgColor,
                     int turtleColor,
                     int penColor,
                     int titleColor,
                     boolean visible,
                     boolean isShown)
Method Detail

init

protected void init()
Initializes Playground. Called by main() if Playground is created before main() is called.


show

public void show()
Shows the form display if it is not yet visible or it was previously hidden by another display. Because it is not garanteed that the diplay is actually visible when Display.setCurrent() returns, wait for a maximum of 5 s for the display to get shown.


show

protected void show(boolean wait)
Shows the graphics display if it was previously hidden by another display or not yet displayed.
If wait = true, block until the display becomes actually visible, up to a maximum auf 5 seconds. This may be useful to observe the start of an animation.


setTracePenColor

protected int setTracePenColor(int color)
Sets color of drawing pen in trace buffer. Returns previous value.


clear

protected void clear(boolean init)
Clears the graphics buffers (fully paint with background color) and draws a surrounding white rectangle. If init = true, set the current graph position to window coordiantes (0, 0).


addLabel

protected void addLabel(java.lang.String text,
                        int x,
                        int y,
                        int index,
                        int color)
Shows the given text with given color left adjusted at given x, y pixel coordinate. Index is used to reference the text for erasing.


drawLabels

protected void drawLabels()

removeLabel

protected void removeLabel(int index)
Removes text with given index.


_line

protected void _line(int x1,
                     int y1,
                     int x2,
                     int y2)
Draws a line with given pixel coordinates into trace buffer and sets the graph position to the endpoint.


line

protected void line(double x1,
                    double y1,
                    double x2,
                    double y2)
Draws a line into trace buffer with given window coordinates into given buffer and sets the graph position to the endpoint.


_draw

protected void _draw(int x,
                     int y)
Draws a line into trace buffer from current graph position to given pixel coordinates and sets the graph position to the endpoint.


draw

protected void draw(double x,
                    double y)
Draws a line into trace buffer from current graph position to given window coordinates and sets the graph position to the endpoint.


_move

protected void _move(int x,
                     int y)
Sets the current graph position into trace buffer to given pixel coordinates (without drawing anything).


move

protected void move(double x,
                    double y)
Sets the current graph position in trace buffer to given window coordinates (without drawing anything).


_triangle

protected void _triangle(int x1,
                         int y1,
                         int x2,
                         int y2,
                         int x3,
                         int y3)
Draws a triangle with given corners in pixel coordintates. The graph position is unchanged.


triangle

protected void triangle(double x1,
                        double y1,
                        double x2,
                        double y2,
                        double x3,
                        double y3)
Draws a triangle with given corners in window coordintates. The graph position is unchanged.


_fillTriangle

protected void _fillTriangle(int x1,
                             int y1,
                             int x2,
                             int y2,
                             int x3,
                             int y3,
                             int color)
Draws a filled triangle with given corners in pixel coordintates into trace buffer using the given color. The graph position is unchanged.


fillTriangle

protected void fillTriangle(double x1,
                            double y1,
                            double x2,
                            double y2,
                            double x3,
                            double y3,
                            int color)
Draws a filled triangle with given corners in window coordintates using the given color. The graph position is unchanged.


_rectangle

protected void _rectangle(int ulx,
                          int uly,
                          int lrx,
                          int lry)
Draws a rectangle with given opposite corners in pixel coordinates into trace buffer. ulx: upper left x uly: upper left y lrx: lower right x lry: lower right y The graph position is unchanged.


rectangle

protected void rectangle(double x1,
                         double y1,
                         double x2,
                         double y2)
Draws a rectangle with given opposite corners in window coordinates. The graph position is unchanged.


_fillRectangle

protected void _fillRectangle(int ulx,
                              int uly,
                              int lrx,
                              int lry,
                              int color)
Draws a filled rectangle with given opposite corners in pixel coordinates into trace buffer using the given color. ulx: upper left x uly: upper left y lrx: lower right x lry: lower right y The graph position is unchanged.


fillRectangle

protected void fillRectangle(double x1,
                             double y1,
                             double x2,
                             double y2,
                             int color)
Draws a filled rectangle with given opposite corners in window coordinates using the given color. The graph position is unchanged.


window

protected void window(double xmin,
                      double xmax,
                      double ymin,
                      double ymax)
Sets window coordinates. left_x, right_x, bottom_y, top_y


toPixelX

protected int toPixelX(double windowX)
Converts window coordinates to pixel coordinates (horizontal).


toPixelY

protected int toPixelY(double windowY)
Converts window coordinates to pixel coordinates (vertical).


toPixelWidth

protected int toPixelWidth(double windowWidth)
Converts window coordinates increment to pixel coordinates increment (horizontal). Increment is always positive.


toPixelHeight

protected int toPixelHeight(double windowHeight)
Converts window coordinates increment to pixel coordinates increment (vertical). Increment is always positive.


toWindowX

protected double toWindowX(int userX)
Converts pixel coordinates to window coordinates (horizontal).


toWindowY

protected double toWindowY(int userY)
Converts pixel coordinates to window coordinates (vertical).


toWindowWidth

protected double toWindowWidth(int pixelWidth)
Converts pixel coordinates increment to window coordinates increment (horizontal). Increment is always positive.


toWindowHeight

protected double toWindowHeight(int pixelHeight)
Converts pixel coordinates increment to window coordinates increment (vertical). Increment is always positive.


getAspectRatio

protected double getAspectRatio()
Returns the ratio of canvas height to width.


_getPosX

protected int _getPosX()
Returns pixel coordinate x of current graph position.


getPosX

protected double getPosX()
Returns window coordinate x of current graph position.


_getPosY

protected int _getPosY()
Returns pixel coordinate y of current graph position.


getPosY

protected double getPosY()
Returns window coordinate y of current graph position.


getTurtleBuffer

protected javax.microedition.lcdui.Graphics getTurtleBuffer()
Returns the graphics turtle buffer.


getTraceBuffer

protected javax.microedition.lcdui.Graphics getTraceBuffer()
Returns the graphics turtle buffer.


getTurtleImage

protected javax.microedition.lcdui.Image getTurtleImage()
Returns the turtle image.


getTraceImage

protected javax.microedition.lcdui.Image getTraceImage()
Returns the trace image.


addKeyListener

protected void addKeyListener(KeyListener keyListener)
Registers an KeyListener to get a notification when a button is clicked.


removeKeyListener

protected void removeKeyListener()
Removes a registered KeyListener.


_image

protected boolean _image(java.lang.String imageUrl,
                         int x,
                         int y)
Puts the PNG image into turtle buffer from given file url at given pixel coordinates (specifies upper left corner of image). Returns true if successful.


image

protected boolean image(java.lang.String imageUrl,
                        double x,
                        double y)
Puts the PNG image into turtle buffer from given file url at given window coordinates (specifies upper left corner of image). Returns true if successful.


_imageWidth

protected int _imageWidth(java.lang.String imageUrl)
Returns the width (horizontal size) of the PNG image from the given url (in pixel coordinates). Returns 0, if PNG image is invalid.


imageWidth

protected double imageWidth(java.lang.String imageUrl)
Returns the width (horizontal size) of the PNG image from the given url (in window coordinates). Returns 0, if PNG image is invalid.


_imageHeight

protected int _imageHeight(java.lang.String imageUrl)
Returns the height (vertical size) of the PNG image from the given url (in pixel coordinates). Returns 0, if PNG image is invalid.


imageHeight

protected double imageHeight(java.lang.String imageUrl)
Returns the height (vertical size) of the PNG image from the given url (in window coordinates). Returns 0, if PNG image is invalid.


_screenWidth

protected int _screenWidth()
Returns width of screen in pixel coordinates. Pixel coordinates 0 up to this value (inclusive) Number of pixels: this value + 1


screenResolutionX

protected int screenResolutionX()
Returns number of pixels in horizontal direction.


screenWidth

protected double screenWidth()
Returns width of screen in window coordinates.


_screenHeight

protected int _screenHeight()
Returns height of screen in pixel coordinates. Pixel coordinates 0 up to this value (inclusive) Number of pixels: this value + 1


screenResolutionY

protected int screenResolutionY()
Returns number of pixels in vertical direction.


screenHeight

protected double screenHeight()
Returns height of screen in window coordinates.


paint

protected void paint(javax.microedition.lcdui.Graphics g)
Used for rendering canvas.

Specified by:
paint in class javax.microedition.lcdui.Canvas

keyPressed

protected void keyPressed(int keyCode)
Used to get key events.

Overrides:
keyPressed in class javax.microedition.lcdui.Canvas

keyReleased

protected void keyReleased(int keyCode)
Used to get key events.

Overrides:
keyReleased in class javax.microedition.lcdui.Canvas

keyRepeated

protected void keyRepeated(int keyCode)
Used to get key events.

Overrides:
keyRepeated in class javax.microedition.lcdui.Canvas

addOkButton

public void addOkButton()
Adds an OK soft button with label "OK". When pressed, the Gidlet's callback notification doOk() is called unless you register your own CommandListener.


addOkButton

public void addOkButton(java.lang.String label)
Adds an OK soft button with given label. When pressed, the Gidlet's callback notification doOk() is called unless you register your own CommandListener.


removeExitButton

public void removeExitButton()
Removes Exit soft button. Gidlet's callback notifications doExit() is disabled.


removeOkButton

public void removeOkButton()
Removes OK soft button. Gidlet's callback notification doOk() is disabled.