| 
 | MIDP3.0 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.microedition.lcdui.Displayable
javax.microedition.lcdui.Canvas
public abstract class Canvas
The Canvas class is a base class for writing applications that
 need to handle low-level events and to issue graphics calls for drawing to
 the display. Game applications will likely make heavy use of the
 Canvas class. From an application development perspective, the
 Canvas class is interchangeable with standard
 Screen classes, so an application may mix and match
 Canvas with high-level screens as needed. For example, a List
 screen may be used to select the track for a racing game, and a
 Canvas subclass would implement the actual game.
 
 The Canvas provides the developer with methods to handle
 actions, key events, and pointer events (if supported by the device). Methods
 are also provided to identify the device's capabilities and mapping of keys
 to actions. The key events are reported with respect to
 key codes, which are directly bound to concrete keys on the
 device, use of which may hinder portability. Portable applications should use
 actions instead of key codes.
 
 Like other subclasses of Displayable, the Canvas
 class allows the application to register a listener for commands. Unlike
 other Displayables, however, the Canvas class
 requires applications to subclass it in order to use it. The
 paint() method is declared abstract, and so
 the application must provide an implementation in its subclass.
 Other event-reporting methods are not declared abstract, and
 their default implementations are empty (that is, they do nothing). This
 allows the application to override only the methods that report events in
 which the application has interest.
 
 This is in contrast to the Screen classes, which allow the
 application to define listeners and to register them with instances of the
 Screen classes. This style is not used for the
 Canvas class, because several new listener interfaces would
 need to be created, one for each kind of event that might be delivered. An
 alternative would be to have fewer listener interfaces, but this would
 require listeners to filter out events in which they had no interest.
 
 CanvasItem subclasses, such as a TextEditor, may be drawn on
 Canvas or CustomItem. See CanvasItem and
 TextEditor for more details.
 
 Applications receive keystroke events in which the individual keys are named
 within a space of key codes. Every key for which events are
 reported to MIDP applications is assigned a key code. The key code values are
 unique for each hardware key unless two keys are obvious synonyms for each
 other. MIDP defines the following key codes: KEY_NUM0,
 KEY_NUM1, KEY_NUM2,
 KEY_NUM3, KEY_NUM4,
 KEY_NUM5, KEY_NUM6,
 KEY_NUM7, KEY_NUM8,
 KEY_NUM9, KEY_STAR, and
 KEY_POUND.
 (These key codes correspond to keys on a ITU-T standard telephone keypad.)
 Other keys may be present on the keyboard, and they will generally have key
 codes distinct from those list above. In order to guarantee portability,
 applications should use only the standard key codes.
 
The standard key codes' values are equal to the Unicode encoding for the character that represents the key. If the device includes any other keys that have an obvious correspondence to a Unicode character, their key code values should equal the Unicode encoding for that character. For keys that have no corresponding Unicode character, the implementation must use negative values. Zero is defined to be an invalid key code. It is thus possible for an application to convert a keyCode into a Unicode character using the following code:
 if (keyCode > 0) {
  char ch = (char) keyCode;
  // ...
 }
 
 This technique is useful only in certain limited cases. In particular, it is
 not sufficient for full textual input, because it does not handle upper and
 lower case, keyboard shift states, and characters that require more than one
 keystroke to enter. For textual input, applications should always use
 TextBox or TextField objects.
 
 It is sometimes useful to find the name of a key in order to
 display a message about this key. In this case the application may use the
 getKeyName() method to find a key's name.
 
 Portable applications that need soft key and arrow events and action-related events
 should use actions in preference to key codes and key names.
 Soft key codes are mapped to actions defined by
 exact placement values as specified for the
 Exact placement of Commands.
 Navigation and game keys are mapped to the actions: UP, DOWN,
 LEFT, RIGHT, FIRE,
 GAME_A, GAME_B, GAME_C,
 and GAME_D.
 
 Each key code may be mapped to at most one action. However, an
 action may be associated with more than one key code. The application can
 translate a key code into an action using the getGameAction(int keyCode) method, and it can translate an action into a
 key code using the getKeyCode(int gameAction)
 method. There may be multiple keycodes associated with a particular
 action, but getKeyCode returns only one of them. Supposing
 that g is a valid action and k is a valid
 key code for a key associated with a action, consider the following
 expressions:
 
g == getGameAction(getKeyCode(g)) // (1) k == getKeyCode(getGameAction(k)) // (2)
Expression (1) is always true. However, expression (2) might be true but is not necessarily true.
 Portable applications that are interested in using actions should
 translate every key event into an action by calling the getGameAction() method and then testing the result. For
 example, on some devices the actions UP,
 DOWN, LEFT and RIGHT may be
 mapped to 4-way navigation arrow keys. In this case,
 getKeyCode(UP)
 would return a device-dependent code for the up-arrow key. On other devices,
 a possible mapping would be on the number keys 2,
 4, 6 and 8. In this case,
 getKeyCode(UP) would return KEY_NUM2. In both
 cases, the getGameAction() method would return the
 LEFT action when the user presses the key that is a
 "natural left" on her device.
 
 The implementation is not allowed to change the mapping of actions and
 key codes during execution of the application. However, if the device keypad
 can be used in different modes, and some modes restrict
 user access to certain keys, or if the device has several different keypads
 that are not meant to used simultaneously, a mobile handset implementation is
 NOT REQUIRED to ensure that the mapping between key codes and action
 does not change during the execution of the application. Consequently, applications
 should use the getGameAction() method to determine which
 action is associated with a given key code. It is recommended that applications
 avoid using the getKeyCode() method to determine which key
 is assigned to a specific action.
 
 It is also possible for the user to issue Commands when a
 Canvas is current. Commands are mapped to keys and menus in a
 device-specific fashion. For some devices the keys used for commands may
 overlap with the keys that will deliver key code events to the canvas. If
 this is the case, the device will provide a means transparent to the
 application that enables the user to select a mode that determines whether
 these keys will deliver commands or key code events to the application. When
 the Canvas is in normal mode (see below),
 the set of key code events available to a canvas will not change depending
 upon the number of commands present or the presence of a command listener.
 When the Canvas is in full-screen mode, if there is no command
 listener present, the device MUST deliver key code events for keys
 that would otherwise be reserved for delivery of commands. Game developers
 should be aware that access to commands will vary greatly across devices, and
 that requiring the user to issue commands during game play may have a great
 impact on the ease with which the game can be played.
 
 The Canvas object defines several methods that are called by
 the implementation. These methods are primarily for the purpose of delivering
 events to the application, and so they are referred to as
 event delivery methods. The set of methods is:
 
showNotify() hideNotify() keyPressed() keyRepeated() keyReleased() pointerPressed() pointerDragged() pointerReleased() paint() 
 These methods are all called serially. That is, the implementation will never
 call an event delivery method before a prior call to any of the
 event delivery methods has returned. The serviceRepaints()
 method is an exception to this rule, as it blocks until paint()
 is called and returns. This will occur even if the application is in the
 midst of one of the event delivery methods when it calls
 serviceRepaints().
 
 The Display.callSerially() method can be used to
 serialize some application-defined work with the event stream. For further
 information, see the Event Handling
 and Concurrency sections of
 the package summary.
 
 The key-related, pointer-related, and paint() methods will
 only be called while the Canvas is actually visible on the
 output device. These methods will therefore only be called on this
 Canvas object only after a call to showNotify()
 and before a call to hideNotify(). After
 hideNotify() has been called, none of the key, pointer, and
 paint methods will be called until after a subsequent call to
 showNotify() has returned. A call to a run()
 method resulting from callSerially() may occur irrespective of
 calls to showNotify() and hideNotify().
 
 The showNotify() method is called prior to the
 Canvas actually being made visible on the display, and the
 hideNotify() method is called after the
 Canvas has been removed from the display. The visibility state
 of a Canvas (or any other Displayable object)
 may be queried through the use of the Displayable.isShown() method. The change in visibility state of a
 Canvas may be caused by the application management software
 moving MIDlets between foreground and background states, or by
 the system obscuring the Canvas with system screens. Thus, the
 calls to showNotify() and hideNotify() are not
 under the control of the MIDlet and may occur fairly
 frequently. Application developers are encouraged to perform expensive setup
 and teardown tasks outside the showNotify() and
 hideNotify() methods in order to make them as lightweight as
 possible.
 
 A Canvas can be in normal mode or in full-screen mode. In
 normal mode, space on the display may be occupied by command labels, a title,
 and a ticker. By setting a Canvas into full-screen mode, the
 application is requesting that the Canvas occupy as much of
 the display space as is possible. In full-screen mode, the title and ticker
 are not displayed even if they are present on the Canvas, and
 Commands may be presented using some alternative means (such
 as through a pop-up menu). Note that the implementation may still consume a
 portion of the display for things like status indicators, even if the
 displayed Canvas is in full-screen mode. In full-screen mode,
 although the title is not displayed, its text may still be used for other
 purposes, such as for the title of a pop-up menu of Commands.
 
 Canvas objects are in normal mode by default. The normal vs.
 full-screen mode setting is controlled through the use of the setFullScreenMode(boolean) method.
 
 Calling setFullScreenMode(boolean) may result in
 sizeChanged() being called. The default
 implementation of this method does nothing. The application can override this
 method to handle changes in size of available drawing area.
 
 Note: As mentioned in the "Specification
 Requirements" section of the overview, implementations must provide the
 user with an indication of network usage. If the indicator is rendered on
 screen, it must be visible when network activity occurs, even when the
 Canvas is in full-screen mode.
 
| Field Summary | |
|---|---|
| static int | ACTIONS_ALLConstant for requesting the full set of actions comprised of UP, DOWN, LEFT, RIGHT, FIRE, GAME_A, GAME_B, GAME_C, and GAME_D. | 
| static int | ACTIONS_NAVIGATIONConstant for requesting the basic set of actions comprised of UP, DOWN, LEFT, RIGHT, and FIRE ACTIONS_NAVIGATION has a value of -1. | 
| static int | ACTIONS_NONEConstant for requesting the empty set of actions ACTIONS_NONE has a value of 0. | 
| static int | DOWNConstant for the DOWNaction. | 
| static int | FIREConstant for the FIREaction. | 
| static int | GAME_AConstant for the general purpose " A"
 action. | 
| static int | GAME_BConstant for the general purpose " B"
 action. | 
| static int | GAME_CConstant for the general purpose " C"
 action. | 
| static int | GAME_DConstant for the general purpose " D"
 action. | 
| static int | KEY_BACKSPACEkeyCode for the backspace key, U+0008 BACKSPACE. | 
| static int | KEY_DELETEkeyCode for the delete key, U+007F DELETE. | 
| static int | KEY_DOWNkeyCode for the down key. | 
| static int | KEY_ENTERkeyCode for the enter key, U+000A LINE FEED. | 
| static int | KEY_ESCAPEkeyCode for the escape key, U+001B ESCAPE. | 
| static int | KEY_LEFTkeyCode for the left key. | 
| static int | KEY_NUM0keyCode for ITU-T key 0. | 
| static int | KEY_NUM1keyCode for ITU-T key 1. | 
| static int | KEY_NUM2keyCode for ITU-T key 2. | 
| static int | KEY_NUM3keyCode for ITU-T key 3. | 
| static int | KEY_NUM4keyCode for ITU-T key 4. | 
| static int | KEY_NUM5keyCode for ITU-T key 5. | 
| static int | KEY_NUM6keyCode for ITU-T key 6. | 
| static int | KEY_NUM7keyCode for ITU-T key 7. | 
| static int | KEY_NUM8keyCode for ITU-T key 8. | 
| static int | KEY_NUM9keyCode for ITU-T key 9. | 
| static int | KEY_POUNDkeyCode for ITU-T key "pound" ( #). | 
| static int | KEY_RIGHTkeyCode for the right key. | 
| static int | KEY_SELECTkeyCode for the select key. | 
| static int | KEY_SPACEkeyCode for the space key, U+0020 SPACE. | 
| static int | KEY_STARkeyCode for ITU-T key "star" ( *). | 
| static int | KEY_TABkeyCode for the tabulation key, U+0009 HORIZONTAL TABULATION. | 
| static int | KEY_UPkeyCode for the up key. | 
| static int | LEFTConstant for the LEFTaction. | 
| static int | RIGHTConstant for the RIGHTaction. | 
| static int | UPConstant for the UPaction. | 
| Constructor Summary | |
|---|---|
| protected  | Canvas()Constructs a new Canvasobject | 
| Method Summary | |
|---|---|
|  int | getGameAction(int keyCode)Gets the action associated with the given key code of the device. | 
|  int | getHeight()Gets the height in pixels of the displayable area of the Canvas. | 
|  int | getKeyCode(int action)Gets a key code that corresponds to the specified action on the device. | 
|  java.lang.String | getKeyName(int keyCode)Gets an informative key string for a key. | 
|  int[] | getSoftkeyLabelCoordinates(int placement)Gets the upper-left coordinates on the Canvas coordinate system, width, and height of the given placement. | 
|  int | getWidth()Gets the width in pixels of the displayable area of the Canvas. | 
|  boolean | hasPointerEvents()Deprecated. Support for pointer press and release events are determined by the  Display . UseDisplay.hasPointerevents() | 
|  boolean | hasPointerMotionEvents()Deprecated. Support for pointer motion events are determined by the  Display . UseDisplay.hasPointerMotionevents() | 
|  boolean | hasRepeatEvents()Checks if the platform can generate repeat events when key is kept down. | 
| protected  void | hideNotify()The implementation calls hideNotify()shortly after theCanvashas been removed from the display. | 
|  boolean | isDoubleBuffered()Checks if the Canvasis double buffered by the
 implementation. | 
| protected  void | keyPressed(int keyCode)Called when a key is pressed. | 
| protected  void | keyReleased(int keyCode)Called when a key is released. | 
| protected  void | keyRepeated(int keyCode)Called when a key is repeated (held down). | 
| protected abstract  void | paint(Graphics g)Renders the Canvas. | 
| protected  void | pointerDragged(int x,
               int y)Called when the pointer is dragged. | 
| protected  void | pointerPressed(int x,
               int y)Called when the pointer is pressed. | 
| protected  void | pointerReleased(int x,
                int y)Called when the pointer is released. | 
|  void | repaint()Requests a repaint for the entire Canvas. | 
|  void | repaint(int x,
        int y,
        int width,
        int height)Requests a repaint for the specified region of the Canvas. | 
|  void | serviceRepaints()Forces any pending repaint requests to be serviced immediately. | 
|  void | setFullScreenMode(boolean mode)Controls whether the Canvasis in full-screen mode or in
 normal mode. | 
|  void | setKeyListener(KeyListener listener)Sets a key listener for key events to this Canvas, replacing any previous KeyListener. | 
|  void | setPaintMode(boolean opaque)Sets the paint mode for this Canvas. | 
|  void | setRequiredActions(int actionSet)Specifies the set of actions that must be available on touch screen devices while this Canvas is current on the foreground Display. | 
| protected  void | showNotify()The implementation calls showNotify()immediately prior to
 thisCanvasbeing made visible on the display. | 
| protected  void | sizeChanged(int w,
            int h)Called when the drawable area of the Canvashas
 been changed. | 
| Methods inherited from class javax.microedition.lcdui.Displayable | 
|---|
| addCommand, getCommand, getCommandLayoutPolicy, getCommands, getCurrentDisplay, getMenu, getTicker, getTitle, invalidateCommandLayout, isShown, removeCommand, removeCommandOrMenu, setCommand, setCommandLayoutPolicy, setCommandListener, setMenu, setTicker, setTitle | 
| Methods inherited from class java.lang.Object | 
|---|
| equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
|---|
public static final int UP
UP action.
 
 Constant value 1 is set to UP.
 
public static final int DOWN
DOWN action.
 
 Constant value 6 is set to DOWN.
 
public static final int LEFT
LEFT action.
 
 Constant value 2 is set to LEFT.
 
public static final int RIGHT
RIGHT action.
 
 Constant value 5 is set to RIGHT.
 
public static final int FIRE
FIRE action.
 
 Constant value 8 is set to FIRE.
 
public static final int GAME_A
A"
 action.
 
 Constant value 9 is set to GAME_A.
 
public static final int GAME_B
B"
 action.
 
 Constant value 10 is set to GAME_B.
 
public static final int GAME_C
C"
 action.
 
 Constant value 11 is set to GAME_C.
 
public static final int GAME_D
D"
 action.
 
 Constant value 12 is set to GAME_D.
 
public static final int KEY_NUM0
0.
 
 Constant value 48 is set to KEY_NUM0.
 
public static final int KEY_NUM1
1.
 
 Constant value 49 is set to KEY_NUM1.
 
public static final int KEY_NUM2
2.
 
 Constant value 50 is set to KEY_NUM2.
 
public static final int KEY_NUM3
3.
 
 Constant value 51 is set to KEY_NUM3.
 
public static final int KEY_NUM4
4.
 
 Constant value 52 is set to KEY_NUM4.
 
public static final int KEY_NUM5
5.
 
 Constant value 53 is set to KEY_NUM5.
 
public static final int KEY_NUM6
6.
 
 Constant value 54 is set to KEY_NUM6.
 
public static final int KEY_NUM7
7.
 
 Constant value 55 is set to KEY_NUM7.
 
public static final int KEY_NUM8
8.
 
 Constant value 56 is set to KEY_NUM8.
 
public static final int KEY_NUM9
9.
 
 Constant value 57 is set to KEY_NUM09.
 
public static final int KEY_STAR
*).
 
 Constant value 42 is set to KEY_STAR.
 
public static final int KEY_POUND
#).
 
 Constant value 35 is set to KEY_POUND.
 
public static final int KEY_UP
 Constant value -1 is set to KEY_UP.
 
public static final int KEY_DOWN
 Constant value -2 is set to KEY_DOWN.
 
public static final int KEY_LEFT
 Constant value -3 is set to KEY_LEFT.
 
public static final int KEY_RIGHT
 Constant value -4 is set to KEY_RIGHT.
 
public static final int KEY_SELECT
 Constant value -5 is set to KEY_SELECT.
 
public static final int KEY_ENTER
 Constant value 10 is set to KEY_ENTER.
 
public static final int KEY_SPACE
 Constant value 32 is set to KEY_SPACE.
 
public static final int KEY_BACKSPACE
 Constant value 8 is set to KEY_BACKSPACE.
 
public static final int KEY_DELETE
 Constant value 127 is set to KEY_DELETE.
 
public static final int KEY_ESCAPE
 Constant value 27 is set to KEY_ESCAPE.
 
public static final int KEY_TAB
 Constant value 9 is set to KEY_TAB.
 
public static final int ACTIONS_NONE
public static final int ACTIONS_NAVIGATION
public static final int ACTIONS_ALL
| Constructor Detail | 
|---|
protected Canvas()
Canvas object
| Method Detail | 
|---|
public int getWidth()
Canvas. The displayable area is the area that can be
 directly drawn on by the Canvas Graphics object. The value returned may
 change during execution.
 If it does, the application will be notified through a call to the
 sizeChanged(int, int) method. If setCurrent() has not yet been called to
 associate this Canvas object with a particular display, this call returns
 the width of the primary display. In fullScreenMode, the width is the same
 as the value returned by Display.getWidth().
getWidth in class Displayablepublic int getHeight()
Canvas.  The displayable area is the area that can be
 directly drawn on by the Canvas Graphics object. The value returned may change during execution.
 If it does, the application will be notified through a call to the
 sizeChanged(int, int) method. If setCurrent() has not yet been called to
 associate this Canvas object with a particular display, this call returns
 the height of the primary display.  In fullScreenMode, the height is the same
 as the value returned by Display.getHeight().
getHeight in class Displayablepublic boolean isDoubleBuffered()
Canvas is double buffered by the
 implementation. All implementations MUST support double buffered
 graphics.
true alwayspublic boolean hasPointerEvents()
 Display . Use
   Display.hasPointerevents()
 Display  to which the  Canvas 
 is set to be visible on, using
 Display.setCurrent(),
 supports pointer press and release events.
 Pointer press and release events MUST be supported if the underlying
 hardware supports this feature. If
 setCurrent()
 has not yet been called to associate this  Canvas  object
 with a particular display, this call returns information based on the
 primary display.
true if the device supports pointer events If the
         underlying hardware supports pointer events then the return value
         shall always be true.public boolean hasPointerMotionEvents()
 Display . Use
    Display.hasPointerMotionevents()
 Display  to which the  Canvas 
 is set to be visible on, using
 Display.setCurrent(),
 supports pointer motion events (pointer dragged).
 Applications may use this method to determine if the associated
  Display  is capable of supporting motion events.
 Pointer motion events MUST be supported if the underlying hardware supports
 this feature. If
 setCurrent()
 has not yet been called to associate this  Canvas  object
 with a particular display, this call returns information based on the
 primary display.
true if the device supports pointer motion events.
         If the underlying hardware supports pointer motion events then
         the return value shall always be true.public boolean hasRepeatEvents()
true alwayspublic int getKeyCode(int action)
getGameAction(int) and then interpret the resulting action,
 instead of generating a table of key codes at using this method during
 initialization.
 Valid soft key actions are those placements returned from
 Display.getExactPlacementPositions
 for any of the borders as defined in
 Exact placement of Commands.
 
The mapping between key codes and actions will not change during the execution of the application. (Note: Follow link to the last paragraph in Actions section for a description of an exception case)
action - the action
java.lang.IllegalArgumentException - if action is not a valid actionpublic java.lang.String getKeyName(int keyCode)
F1 through F4, calling this method on the
 keyCode for the F1 key will return the
 string "F1". A typical use for this string
 will be to compose help text such as "Press F1 to
 proceed."
 This method will return a non-empty string for every valid key code.
 There is no direct mapping from actions to key names. To get the
 string name for an action GAME_A, the application
 must call
 
 getKeyName(getKeyCode(GAME_A));
 
keyCode - the key code being requested
java.lang.IllegalArgumentException - if keyCode is not a valid key codepublic int getGameAction(int keyCode)
The mapping between key codes and actions will not change during the execution of the application. (Note: Follow link to the last paragraph in the Actions section for a description of an exception case)
keyCode - the key code
0 if none
java.lang.IllegalArgumentException - if keyCode is not a valid key codepublic void setFullScreenMode(boolean mode)
Canvas is in full-screen mode or in
 normal mode. If Canvas is in full-screen mode, the following requirements
 apply:
 
mode - true if the Canvas is to be in
            full screen mode, false otherwiseprotected void keyPressed(int keyCode)
 The getGameAction() method can be called to determine what
 action, if any, is mapped to the key. Class Canvas
 has an empty implementation of this method, and the subclass has to
 redefine it if it wants to listen this method.
keyCode - the key code of the key that was pressedprotected void keyRepeated(int keyCode)
 The getGameAction() method can be called to determine what
 action, if any, is mapped to the key. Class Canvas
 has an empty implementation of this method, and the subclass has to
 redefine it if it wants to listen this method.
 
keyCode - the key code of the key that was repeatedhasRepeatEvents()protected void keyReleased(int keyCode)
 The getGameAction() method can be called to determine what
 action, if any, is mapped to the key. Class Canvas
 has an empty implementation of this method, and the subclass has to
 redefine it if it wants to listen this method.
 
keyCode - the key code of the key that was released
protected void pointerPressed(int x,
                              int y)
 The hasPointerEvents() method may be called
 to determine if the device supports pointer events. Class
 Canvas has an empty implementation of this method, and the
 subclass has to redefine it if it wants to listen this method.
 
x - the horizontal location where the pointer was pressed
            (relative to the Canvas)y - the vertical location where the pointer was pressed (relative
            to the Canvas)
protected void pointerReleased(int x,
                               int y)
 The hasPointerEvents() method may be called
 to determine if the device supports pointer events. Class
 Canvas has an empty implementation of this method, and the
 subclass has to redefine it if it wants to listen this method.
 
x - the horizontal location where the pointer was released
            (relative to the Canvas)y - the vertical location where the pointer was released (relative
            to the Canvas)
protected void pointerDragged(int x,
                              int y)
 The hasPointerMotionEvents() method may
 be called to determine if the device supports pointer events. Class
 Canvas has an empty implementation of this method, and the
 subclass has to redefine it if it wants to listen this method.
 
x - the horizontal location where the pointer was dragged
            (relative to the Canvas)y - the vertical location where the pointer was dragged (relative
            to the Canvas)
public final void repaint(int x,
                          int y,
                          int width,
                          int height)
Canvas.
 Calling this method may result in subsequent call to paint(),
 where the passed Graphics object's clip region will
 include at least the specified region.
 If the canvas is not visible, or if width and height are zero or less, or if the rectangle does not specify a visible region of the display, this call has no effect.
 The call to paint() occurs asynchronously of the call to
 repaint(). That is, repaint() will not
 block waiting for paint() to finish. The
 paint() method will either be called after the caller of
 repaint() returns to the implementation (if the caller is
 a callback) or on another thread entirely.
 
 To synchronize with its paint() routine, applications can
 use either Display.callSerially()
 or serviceRepaints(), or they can code
 explicit synchronization into their paint() routine.
 
 The origin of the coordinate system is above and to the left of the pixel
 in the upper left corner of the displayable area of the
 Canvas. The X-coordinate is positive right and the
 Y-coordinate is positive downwards.
 
x - the x coordinate of the rectangle to be repaintedy - the y coordinate of the rectangle to be repaintedwidth - the width of the rectangle to be repaintedheight - the height of the rectangle to be repaintedDisplay.callSerially(Runnable), 
serviceRepaints()public final void repaint()
Canvas. The effect is
 identical to
 
  repaint(0, 0, getWidth(), getHeight()); 
public final void serviceRepaints()
 Warning: This method blocks until the call to the
 application's paint() method returns. The application has
 no control over which thread calls paint(); it may vary
 from implementation to implementation. If the caller of
 serviceRepaints() holds a lock that the
 paint() method acquires, this may result in deadlock.
 Therefore, callers of serviceRepaints() must not
 hold any locks that might be acquired within the paint()
 method. The Display.callSerially()
 method provides a facility where an application can be called back after
 painting has completed, avoiding the danger of deadlock.
 
Display.callSerially(Runnable)protected void showNotify()
showNotify() immediately prior to
 this Canvas being made visible on the display. Canvas
 subclasses may override this method to perform tasks before being shown,
 such as setting up animations, starting timers, etc. The default
 implementation of this method in class Canvas is empty.
protected void hideNotify()
hideNotify() shortly after the
 Canvas has been removed from the display.
 Canvas subclasses may override this method in order to
 pause animations, revoke timers, etc. The default implementation of this
 method in class Canvas is empty.
protected abstract void paint(Graphics g)
Canvas. The application must implement this
 method in order to paint any graphics.
 
 The Graphics object's clip region defines the area of the
 screen that is considered to be invalid. A correctly-written
 paint() routine must paint every pixel within
 this region, unless the paint mode has been set to transparent (see Canvas.setPaintMode).
 This is necessary because the implementation is not required
 to clear the region prior to calling paint() on it. Thus,
 failing to paint every pixel may result in a portion of the previous
 screen image remaining visible.
 
 Applications must not assume that they know the underlying
 source of the paint() call and use this assumption to
 paint only a subset of the pixels within the clip region. The reason is
 that this particular paint() call may have resulted from
 multiple repaint() requests, some of which may have been
 generated from outside the application. An application that paints only
 what it thinks is necessary to be painted may display incorrectly if the
 screen contents had been invalidated by, for example, an incoming
 telephone call.
 
 Operations on this graphics object after the paint()
 call
 returns are undefined. Thus, the application must not cache
 this Graphics object for later use or use by another
 thread. It must only be used within the scope of this method.
 
The implementation may postpone visible effects of graphics operations until the end of the paint method.
 The contents of the Canvas are never saved if it is hidden
 and then is made visible again. Thus, shortly after
 showNotify() is called, paint() will always
 be called with a Graphics object whose clip region
 specifies the entire displayable area of the Canvas.
 Applications must not rely on any contents being preserved
 from a previous occasion when the Canvas was current. This
 call to paint() will not necessarily occur before any
 other key or pointer methods are called on the Canvas.
 Applications whose repaint recomputation is expensive may create an
 offscreen Image, paint into it, and then draw this image
 on the Canvas when paint() is called.
 
 The application code must never call paint(); it is
 called only by the implementation.
 
 The Graphics object passed to the paint()
 method has the following properties:
 
Canvas;Font.getDefaultFont();SOLID;Canvas; andCanvas is visible, that is, a call to
 isShown() will return true.
g - the Graphics object to be used for rendering
            the Canvas
protected void sizeChanged(int w,
                           int h)
Canvas has
 been changed.  This
 method has augmented semantics compared to Displayable.sizeChanged.
 In addition to the causes listed in
 Displayable.sizeChanged, a size change can occur on a
 Canvas because of a change between normal and
 full-screen modes.
If the size of a Canvas changes while it is
 actually visible on the
 display, it may trigger an automatic repaint request.  If this occurs,
 the call to sizeChanged will occur prior to the call to
 paint.  If the Canvas has become smaller, the
 implementation may choose not to trigger a repaint request if the
 remaining contents of the Canvas have been
 preserved.  Similarly, if
 the Canvas has become larger, the implementation
 may choose to trigger
 a repaint only for the new region.  In both cases, the preserved
 contents must remain stationary with respect to the origin of the
 Canvas.  If the size change is significant to the
 contents of the
 Canvas, the application must explicitly issue a
 repaint request for the
 changed areas.  Note that the application's repaint request should not
 cause multiple repaints, since it can be coalesced with repaint
 requests that are already pending.
If the size of a Canvas changes while it is not
 visible, the
 implementation may choose to delay calls to sizeChanged
 until immediately prior to the call to showNotify.  In
 that case, there will be only one call to sizeChanged,
 regardless of the number of size changes.
An application that is sensitive to size changes can update instance
 variables in its implementation of sizeChanged.  These
 updated values will be available to the code in the
 showNotify, hideNotify, and
 paint methods.
sizeChanged in class Displayablew - the new width in pixels of the drawable area of the
 Canvash - the new height in pixels of the drawable area of
 the Canvaspublic void setPaintMode(boolean opaque)
If the paint mode is opaque, the implementation may assume
 that the every pixel in the clip region will be rendered by the
 paint method.  Thus, the implementation does not need to
 clear or reset the pixels to a suitable state prior to calling the
 paint method since they will all be rendered by the
 Canvas.
In this example, the opaque paint mode is used and the paint method renders a white background and black text, thus fully obscuring the device's background wallpaper:
 paint(Graphics g) {
     g.setColor(0xFFFFFF);
     g.fillrect(0, 0, getWidth(), getHeight());
     g.setColor(0x000000);
     g.drawString("Some Text", 10, 10, Graphics.TOP + Graphics.LEFT);
 }
 If the paint mode is transparent, the implementation is
 responsible for appropriately filling the entire clip region prior to
 calling the paint method.  Some devices may
 fill the pixels to a suitable background color, while others may fill
 them with a suitable background image.  Hence, any pixels untouched
 by the paint method will be colored appropriately.  In
 this mode, the paint method does not need to render every
 pixel within the clip region; it should render only those pixels within
 the clip region that it wishes to control the contents of.  By rendering
 a subset of the pixels in this manner, the contents of the Canvas will
 appear rendered on top of the background content provided
 by the implementation.
In this example, the transparent paint mode is used and the paint method renders only the black text, thus making it appear on top of the device's background wallpaper:
 paint(Graphics g) {
     g.setColor(0x000000);
     g.drawString("Some Text", 10, 10, Graphics.TOP + Graphics.LEFT);
 }
 The paint mode is opaque by default.
opaque - true to set the paint mode to opaque, false to set it to
 transparentpaint(javax.microedition.lcdui.Graphics)public void setKeyListener(KeyListener listener)
listener - the new listener, or null to remove a listener.public void setRequiredActions(int actionSet)
UP, DOWN,
 LEFT, RIGHT, and FIRE) and MAY provide support
 for additional actions (GAME_A, GAME_B, GAME_C,
 and GAME_D).  On touch screen devices, some or all of these actions may be
 provided using an on-screen keypad, and this method may be used to specify the specific set
 of actions required, thereby permitting the implementation to optimize the size of the
 on-screen keypad.  Calls to this method should be ignored by keypad devices that do not
 include a touch screen.
 By default, the required set of actions is set to ACTIONS_NAVIGATION,
 and the implementation MUST ensure that at least the basic actions (UP,
 DOWN, LEFT, RIGHT, and FIRE) are
 supported.  If the required set of actions is set to ACTIONS_ALL, the implementation
 MUST ensure that all actions (UP, DOWN, LEFT,
 RIGHT, and FIRE GAME_A, GAME_B,
 GAME_C, and GAME_D) are supported.  If the required set of actions
 is set to ACTIONS_NONE, the implementation is not required to support any game
 actions and may hide the on-screen keypad if desired.
 The application may still receive key events for an action even if it is not included in the
 required set.
actionSet - The set of actions required by this Canvas (ACTIONS_NAVIGATION,
 ACTIONS_ALL, or ACTIONS_NONE)
java.lang.IllegalArgumentException - if actionSet is not one of ACTIONS_NAVIGATION,
 ACTIONS_ALL, or ACTIONS_NONEpublic int[] getSoftkeyLabelCoordinates(int placement)
Canvas object with a particular
 Display , this call returns the upper-left coordinates on the primary Display
 coordinate system, width and height for the given placement. In normal mode, this method may return values
 beyond the Canvas width and height or negative values. The method
 only returns coordinates for placements on Display.SOFTKEY_TOP,
 Display.SOFTKEY_BOTTOM, Display.SOFTKEY_LEFT or
 Display.SOFTKEY_RIGHT borders. The method throws
 IllegalArgumentException for placements on the
 Display.SOFTKEY_OFFSCREEN border.
java.lang.IllegalArgumentException - if placement is not valid or if
 valid placement on SOFTKEY_OFFSCREEN border.| 
 | MIDP3.0 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||