|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.microedition.lcdui.Displayable javax.microedition.lcdui.Canvas javax.microedition.lcdui.game.GameCanvas ch.aplu.gidlet.MPanel
public class MPanel
Simple graphics window of full display width and height (client drawing area)
using a coordinate system with x-axis from left to right, y-axis from bottom to top
(called window coordinates, default range 0..1, 0..1).
The drawing methods perform all drawings in an offscreen buffer
and automatically flush it on the display, so the graphics is shown step-by-step.
A current graph position is used, that remembers the end position of the last
drawing process and where new drawings start.
If pixel accuracy is needed, use the graphcis methods starting with _
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.
To avoid flickering in animated graphics, turn automatic flushing off by calling
enableFlush(false). The drawing methods only modifies the offscreen buffer now. Call
flushGraphics() to render it to the display.
main() serves as entry point for the user programm. It is called in the run-method
of a separate thread and should terminate to avoid non-terminated threads.
An instance of MConsole may be created when declaring instance variable of the application
program. To garantee that the initialization is executed in the Gidlet's thread,
these instances are queued and the intialisation takes place in the same order
they are created when main() is started.
Example:
import ch.aplu.gidlet.*;
public class GidletEx3 extends Gidlet
{
public void main()
{
MPanel mp = new MPanel(this, "Chessboard");
mp.window(0, 8, 0, 8);
mp.rectangle(0, 0, 8, 8);
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
if ((i + j) % 2 == 0)
mp.fillRectangle(i, j, i + 1, j + 1);
}
}
More than one instance may be created. The constructor flag visible
may be used, to select if the display is initially shown or hidden.
A hidden display will become visible by calling show(). There is no other way to
make it hidden than showing a different display. All graphics methods may
be called while the display is hidden.
Field Summary |
---|
Fields inherited from class javax.microedition.lcdui.game.GameCanvas |
---|
DOWN_PRESSED, FIRE_PRESSED, GAME_A_PRESSED, GAME_B_PRESSED, GAME_C_PRESSED, GAME_D_PRESSED, LEFT_PRESSED, RIGHT_PRESSED, UP_PRESSED |
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 | |
---|---|
MPanel()
Same as MPanel(visible) with visible = true. |
|
MPanel(boolean visible)
Constructs a MPanel and show the window with no title. |
|
MPanel(double xmin,
double xmax,
double ymin,
double ymax)
Same as MPanel(xmin, xmax, ymin, ymax, visible) with visible = true. |
|
MPanel(double xmin,
double xmax,
double ymin,
double ymax,
boolean visible)
Constructs a MPanel and show the display with no title. |
|
MPanel(java.lang.String title)
Same as MPanel(title, visible) with visible = true. |
|
MPanel(java.lang.String title,
boolean visible)
Constructs a MPanel and show the display with given title. |
|
MPanel(java.lang.String title,
double xmin,
double xmax,
double ymin,
double ymax)
Same as MPanel(title, xmin, xmax, ymin, ymax, visible) with visible = true. |
|
MPanel(java.lang.String title,
double xmin,
double xmax,
double ymin,
double ymax,
boolean visible)
Constructs a MPanel and show the display with given title and given window coordinates, (0, 0) is at lower left corner which is the current graph cursor position. |
Method Summary | |
---|---|
void |
_arc(int width,
int height,
int startAngle,
int arcAngle)
Draws an elliptical arc inside bounding rectangle centered at current graph position with given width and height in pixel coordinates. |
void |
_circle(int radius)
Draws a circle with center at the current graph position and given radius in pixel coordinates. |
int |
_displayHeight()
Returns height of display in pixel coordinates. |
int |
_displayWidth()
Returns width of display in pixel coordinates. |
void |
_draw(int x,
int y)
Draws a line from current graph position to given pixel coordinates and sets the graph position to the endpoint. |
boolean |
_drawImage(java.lang.String imageUrl,
int x,
int y)
Shows the PNG image from given file url at given pixel coordinates (upper left corner of image). |
void |
_drawSprite(javax.microedition.lcdui.game.Sprite sprite,
int x,
int y)
Draws the given sprite at given pixel coordinates (upper left corner of image). |
void |
_fillArc(int width,
int height,
int startAngle,
int arcAngle)
Draws a filled elliptical arc inside bounding rectangle centered at current graph position with given width and height in pixel coordinates. |
void |
_fillCircle(int radius)
Draws a filled circle with center at the current graph position and given radius in pixel coordinates. |
void |
_fillRectangle(int width,
int height)
Draws a filled rectangle with center at the current graph position and given width and height in window coordinates using the current color. |
void |
_fillRectangle(int x1,
int y1,
int x2,
int y2)
Draws a filled rectangle with given opposite corners in pixel coordinates. |
void |
_fillTriangle(int x1,
int y1,
int x2,
int y2,
int x3,
int y3)
Draws a filled triangle with given corners in pixel coordintates using the current color. |
int |
_getPosX()
Returns pixel coordinate x of current graph position. |
int |
_getPosY()
Returns pixel coordinate y of current graph position. |
int |
_imageHeight(java.lang.String imageUrl)
Returns the height (vertical size) of the PNG image from the given url (in pixel coordinates). |
int |
_imageWidth(java.lang.String imageUrl)
Returns the width (horizontal size) of the PNG image from the given url (in pixel coordinates). |
void |
_label(java.lang.String text,
int y)
Draws the given text with current drawing color and font left adjusted at given y pixel coordinate. |
void |
_line(int x1,
int y1,
int x2,
int y2)
Draws a line with given pixel coordinates and sets the graph position to the endpoint. |
void |
_move(int x,
int y)
Sets the current graph position to given pixel coordinates (without drawing anything). |
void |
_point(int x,
int y)
Draws a single point at the given pixel coordinates. |
void |
_rectangle(int width,
int height)
Draws a rectangle with center at the current graph position and given width and height in pixel coordinates. |
void |
_rectangle(int x1,
int y1,
int x2,
int y2)
Draws a rectangle with given opposite corners in pixel coordinates. |
void |
_triangle(int x1,
int y1,
int x2,
int y2,
int x3,
int y3)
Draws a triangle with given corners in pixel coordintates. |
void |
addKeyListener(KeyListener keyListener)
Registers an KeyListener to get a notification when a button is clicked. |
void |
addOkButton()
Adds an OK soft button with label "OK". |
void |
addOkButton(java.lang.String label)
Adds an OK soft button with given label. |
void |
arc(double width,
double height,
int startAngle,
int arcAngle)
Draws an elliptical arc inside bounding rectangle centered at current graph position with given width and height in window coordinates. |
int |
bgColor(int color)
Sets the background color. |
void |
circle(double radius)
Draws a circle with center at the current graph position and given radius in horizontal window coordinates. |
void |
clear()
Clears the graphics window (fully paint with background color) (and the offscreen buffer used by the window). |
int |
color(int color)
Sets the current color of the drawing pen. |
int |
color(int r,
int g,
int b)
Sets the current color of the drawing pen in RGB-format. |
double |
displayHeight()
Returns height of display in window coordinates. |
int |
displayResolutionX()
Return numbers of pixels in horizontal direction. |
int |
displayResolutionY()
Returns number of pixels in vertical direction. |
double |
displayWidth()
Returns width of display in window coordinates. |
void |
draw(double x,
double y)
Draws a line from current graph position to given window coordinates and sets the graph position to the endpoint. |
boolean |
drawImage(java.lang.String imageUrl,
double x,
double y)
Shows the PNG image from given file url at given window coordinates (upper left corner of image). |
void |
drawSprite(javax.microedition.lcdui.game.Sprite sprite,
double x,
double y)
Draws the given sprite at given window coordinates (upper left corner of image). |
boolean |
enableFlush(boolean doFlush)
Enables or disables the automatic flush in graphics methods. |
void |
erase()
Same as clear() but let the current graph position unchanged. |
void |
fillArc(double width,
double height,
int startAngle,
int arcAngle)
Draws a filled elliptical arc inside bounding rectangle centered at current graph position with given width and height in window coordinates. |
void |
fillCircle(double radius)
Draws a filled circle with center at the current graph position and given radius in horizonal window coordinates. |
void |
fillRectangle(double width,
double height)
Draws a filled rectangle with center at the current graph position and given width and height in window coordinates using the current color. |
void |
fillRectangle(double x1,
double y1,
double x2,
double y2)
Draws a filled rectangle with given opposite corners in window coordinates. |
void |
fillTriangle(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Draws a filled triangle with given corners in window coordintates using the current color. |
void |
flush()
Shortcut for flushGraphics() |
double |
getAspectRatio()
Returns the ratio of canvas height to width. |
int |
getBgColor()
Returns the current background color. |
int |
getColor()
Returns the current drawing color. |
javax.microedition.lcdui.Graphics |
getG()
Returns the graphics context. |
javax.microedition.lcdui.Image |
getImage(java.lang.String imageUrl)
Loads image from given resource and returns it's Image reference. |
double |
getPosX()
Returns window coordinate x of current graph position. |
double |
getPosY()
Returns window coordinate y of current graph position. |
javax.microedition.lcdui.game.Sprite |
getSprite(java.lang.String imageUrl)
Loads image from given resource and returns it's Sprite reference. |
javax.microedition.lcdui.game.Sprite |
getSprite(java.lang.String imageUrl,
int frameWidth,
int frameHeight)
Loads image from given resource with given frameWidth, frameHeight and returns it's Sprite reference. |
double |
imageHeight(java.lang.String imageUrl)
Returns the height (vertical size) of the PNG image from the given url (in window coordinates). |
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 MPanel. |
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. |
void |
label(java.lang.String text,
double y)
Draws the given text with current drawing color and font left adjusted at given window y coordinate. |
void |
line(double x1,
double y1,
double x2,
double y2)
Draws a line with given window coordinates and sets the graph position to the endpoint. |
void |
move(double x,
double y)
Sets the current graph position to given window coordinates (without drawing anything). |
void |
point(double x,
double y)
Draws a single point at the given window coordinates. |
void |
rectangle(double width,
double height)
Draws a rectangle with center at the current graph position and given width and height in window coordinates. |
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. |
void |
removeKeyListener()
Removes a registered KeyListener. |
void |
removeOkButton()
Removes Ok soft button. |
void |
restorePanel()
Renders the content of the internal offscreen buffer. |
void |
savePanel()
Saves the current graphics content to an internal offscreen buffer. |
void |
setFont(int face,
int style,
int size)
Sets the current text font for drawing labels. |
void |
show()
Shows the form display if it is not yet visible or it was previously hidden by another display. |
void |
show(boolean wait)
Shows the graphics display if it was previously hidden by another display or not yet displayed. |
void |
title(java.lang.String text)
Draws the given title with current penColor centered in top area of display. |
int |
toPixelHeight(double windowHeight)
Converts window coordinates increment to pixel coordinates increment (vertical). |
int |
toPixelWidth(double windowWidth)
Converts window coordinates increment to pixel coordinates increment (horizontal). |
int |
toPixelX(double windowX)
Converts window coordinates to pixel coordinates (horizontal). |
int |
toPixelY(double windowY)
Converts window coordinates to pixel coordinates (vertical). |
double |
toWindowHeight(int pixelHeight)
Converts pixel coordinates increment to window coordinates increment (vertical). |
double |
toWindowWidth(int pixelWidth)
Converts pixel coordinates increment to window coordinates increment (horizontal). |
double |
toWindowX(int userX)
Converts pixel coordinates to window coordinates (horizontal). |
double |
toWindowY(int userY)
Converts pixel coordinates to window coordinates (vertical). |
void |
triangle(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Draws a triangle with given corners in window coordintates. |
void |
window(double xmin,
double xmax,
double ymin,
double ymax)
Sets window coordinates. |
Methods inherited from class javax.microedition.lcdui.game.GameCanvas |
---|
flushGraphics, flushGraphics, getGraphics, getKeyStates, paint |
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 |
---|
public MPanel(java.lang.String title, double xmin, double xmax, double ymin, double ymax, boolean visible)
public MPanel(java.lang.String title, double xmin, double xmax, double ymin, double ymax)
public MPanel(double xmin, double xmax, double ymin, double ymax, boolean visible)
public MPanel(double xmin, double xmax, double ymin, double ymax)
public MPanel(java.lang.String title, boolean visible)
public MPanel(java.lang.String title)
public MPanel(boolean visible)
public MPanel()
Method Detail |
---|
protected void init()
public void show()
public void show(boolean wait)
public int bgColor(int color)
public int getBgColor()
public int getColor()
public boolean enableFlush(boolean doFlush)
public void clear()
public void erase()
public void _circle(int radius)
public void circle(double radius)
public void _fillCircle(int radius)
public void fillCircle(double radius)
public void _arc(int width, int height, int startAngle, int arcAngle)
public void arc(double width, double height, int startAngle, int arcAngle)
public void _fillArc(int width, int height, int startAngle, int arcAngle)
public void fillArc(double width, double height, int startAngle, int arcAngle)
public int color(int color)
public int color(int r, int g, int b)
public void flush()
public void title(java.lang.String text)
public void _label(java.lang.String text, int y)
color(int)
,
setFont(int, int, int)
public void label(java.lang.String text, double y)
color(int)
,
setFont(int, int, int)
public void _point(int x, int y)
public void point(double x, double y)
public void _line(int x1, int y1, int x2, int y2)
public void line(double x1, double y1, double x2, double y2)
public void _draw(int x, int y)
public void draw(double x, double y)
public void _move(int x, int y)
public void move(double x, double y)
public void _triangle(int x1, int y1, int x2, int y2, int x3, int y3)
public void triangle(double x1, double y1, double x2, double y2, double x3, double y3)
public void _fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
public void fillTriangle(double x1, double y1, double x2, double y2, double x3, double y3)
public void _rectangle(int width, int height)
public void rectangle(double width, double height)
public void _rectangle(int x1, int y1, int x2, int y2)
public void rectangle(double x1, double y1, double x2, double y2)
public void _fillRectangle(int width, int height)
public void fillRectangle(double width, double height)
public void _fillRectangle(int x1, int y1, int x2, int y2)
public void fillRectangle(double x1, double y1, double x2, double y2)
public void window(double xmin, double xmax, double ymin, double ymax)
public int toPixelX(double windowX)
public int toPixelY(double windowY)
public int toPixelWidth(double windowWidth)
public int toPixelHeight(double windowHeight)
public double toWindowX(int userX)
public double toWindowY(int userY)
public double toWindowWidth(int pixelWidth)
public double toWindowHeight(int pixelHeight)
public double getAspectRatio()
public javax.microedition.lcdui.Graphics getG()
public int _getPosX()
public double getPosX()
public int _getPosY()
public double getPosY()
public void addKeyListener(KeyListener keyListener)
public void removeKeyListener()
public javax.microedition.lcdui.Image getImage(java.lang.String imageUrl)
public javax.microedition.lcdui.game.Sprite getSprite(java.lang.String imageUrl)
public javax.microedition.lcdui.game.Sprite getSprite(java.lang.String imageUrl, int frameWidth, int frameHeight)
public void _drawSprite(javax.microedition.lcdui.game.Sprite sprite, int x, int y)
public void drawSprite(javax.microedition.lcdui.game.Sprite sprite, double x, double y)
public boolean _drawImage(java.lang.String imageUrl, int x, int y)
public boolean drawImage(java.lang.String imageUrl, double x, double y)
public int _imageWidth(java.lang.String imageUrl)
public double imageWidth(java.lang.String imageUrl)
public int _imageHeight(java.lang.String imageUrl)
public double imageHeight(java.lang.String imageUrl)
public int _displayWidth()
public int displayResolutionX()
public double displayWidth()
public int _displayHeight()
public int displayResolutionY()
public double displayHeight()
public void setFont(int face, int style, int size)
face
- one of Font.FACE_SYSTEM, Font.FACE_MONOSPACE, or Font.FACE_PROPORTIONALstyle
- Font.STYLE_PLAIN, or a combination of Font.STYLE_BOLD, Font.STYLE_ITALIC, and Font.STYLE_UNDERLINEDsize
- one of Font.SIZE_SMALL, Font.SIZE_MEDIUM, or Font.SIZE_LARGEprotected void keyPressed(int keyCode)
keyPressed
in class javax.microedition.lcdui.Canvas
protected void keyReleased(int keyCode)
keyReleased
in class javax.microedition.lcdui.Canvas
protected void keyRepeated(int keyCode)
keyRepeated
in class javax.microedition.lcdui.Canvas
public void savePanel()
restorePanel()
public void restorePanel()
savePanel()
public void addOkButton()
public void addOkButton(java.lang.String label)
public void removeExitButton()
public void removeOkButton()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |