📄 canvas.java
字号:
return n; } /** * Controls whether the <code>Canvas</code> is in full-screen mode * or in normal mode. * * @param mode <code>true</code> if the <code>Canvas</code> * is to be in full screen mode, <code>false</code> otherwise * * @since MIDP 2.0 */ public void setFullScreenMode(boolean mode) { if (mode == super.fullScreenMode) { return; } super.grabFullScreen(mode); synchronized (Display.LCDUILock) { super.fullScreenMode(mode); } } /** * Called when a key is pressed. * * <P>The <code>getGameAction()</code> method can be called to * determine what game action, if any, is mapped to the key. * Class <code>Canvas</code> has an empty implementation of this method, and * the subclass has to redefine it if it wants to listen this method. * @param keyCode the key code of the key that was pressed */ protected void keyPressed(int keyCode) { } /** * Called when a key is repeated (held down). * * <P>The <code>getGameAction()</code> method can * be called to determine what game action, * if any, is mapped to the key. * Class <code>Canvas</code> has an empty implementation of this method, and * the subclass has to redefine it if it wants to listen this method. * </P> * @param keyCode the key code of the key that was repeated * @see #hasRepeatEvents() */ protected void keyRepeated(int keyCode) { } /** * Called when a key is released. * <P> * The <code>getGameAction()</code> method can be called to * determine what game action, if any, is mapped to the key. * Class <code>Canvas</code> has an empty implementation of this method, and * the subclass has to redefine it if it wants to listen this method. * </P> * @param keyCode the key code of the key that was released */ protected void keyReleased(int keyCode) { } /** * Called when the pointer is pressed. * * <P> * The {@link #hasPointerEvents() hasPointerEvents()} * method may be called to determine if the device supports pointer events. * Class <code>Canvas</code> has an empty implementation of this method, and * the subclass has to redefine it if it wants to listen this method. * </P> * @param x the horizontal location where the pointer was pressed (relative * to the <code>Canvas</code>) * @param y the vertical location where the pointer was pressed * (relative to the <code>Canvas</code>) */ protected void pointerPressed(int x, int y) { } /** * Called when the pointer is released. * * <P> * The {@link #hasPointerEvents() hasPointerEvents()} * method may be called to determine if the device supports pointer events. * Class <code>Canvas</code> has an empty implementation of this method, and * the subclass has to redefine it if it wants to listen this method. * </P> * @param x the horizontal location where the pointer was released * (relative to the <code>Canvas</code>) * @param y the vertical location where the pointer was released * (relative to the <code>Canvas</code>) */ protected void pointerReleased(int x, int y) { } /** * Called when the pointer is dragged. * * <P> * The {@link #hasPointerMotionEvents() hasPointerMotionEvents()} * method may be called to determine if the device supports pointer events. * Class <code>Canvas</code> has an empty implementation of this method, and * the subclass has to redefine it if it wants to listen this method. * </P> * @param x the horizontal location where the pointer was dragged * (relative to the <code>Canvas</code>) * @param y the vertical location where the pointer was dragged * (relative to the <code>Canvas</code>) */ protected void pointerDragged(int x, int y) { } /** * Requests a repaint for the specified region of the * <code>Canvas</code>. Calling * this method may result in subsequent call to * <code>paint()</code>, where the passed * <code>Graphics</code> object's clip region will include at * least the specified * region. * * <p> 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. </p> * * <p> The call to <code>paint()</code> occurs asynchronously of * the call to <code>repaint()</code>. * That is, <code>repaint()</code> will not block waiting for * <code>paint()</code> to finish. The * <code>paint()</code> method will either be called after the * caller of <code>repaint(</code>) * returns * to the implementation (if the caller is a callback) or on another thread * entirely. </p> * * <p> To synchronize with its <code>paint()</code> routine, * applications can use either * {@link Display#callSerially(Runnable) Display.callSerially()} or * {@link #serviceRepaints() serviceRepaints()}, or they can code explicit * synchronization into their <code>paint()</code> routine. </p> * * <p> 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 * <code>Canvas</code>. * The X-coordinate is positive right and the Y-coordinate is * positive downwards. * </p> * * @param x the x coordinate of the rectangle to be repainted * @param y the y coordinate of the rectangle to be repainted * @param width the width of the rectangle to be repainted * @param height the height of the rectangle to be repainted * * @see Display#callSerially(Runnable) * @see #serviceRepaints() */ public final void repaint(int x, int y, int width, int height) { synchronized (Display.LCDUILock) { callRepaint(x + viewport[X], y + viewport[Y], width, height, null); } } /** * Requests a repaint for the entire <code>Canvas</code>. The * effect is identical to * <p> <code> repaint(0, 0, getWidth(), getHeight()); </code> */ public final void repaint() { synchronized (Display.LCDUILock) { callRepaint(viewport[X], viewport[Y], viewport[WIDTH], viewport[HEIGHT], null); } } /** * Forces any pending repaint requests to be serviced immediately. This * method blocks until the pending requests have been serviced. If * there are * no pending repaints, or if this canvas is not visible on the display, * this call does nothing and returns immediately. * * <p><strong>Warning:</strong> This method blocks until the call to the * application's <code>paint()</code> method returns. The * application has no * control over * which thread calls <code>paint()</code>; it may vary from * implementation to * implementation. If the caller of <code>serviceRepaints()</code> * holds a lock that the * <code>paint()</code> method acquires, this may result in * deadlock. Therefore, callers * of <code>serviceRepaints()</code> <em>must not</em> hold any * locks that might be * acquired within the <code>paint()</code> method. The * {@link Display#callSerially(Runnable) Display.callSerially()} * method provides a facility where an application can be called back after * painting has completed, avoiding the danger of deadlock. * </p> * * @see Display#callSerially(Runnable) */ public final void serviceRepaints() { // SYNC NOTE: unlike most public API methods, no locking is done // here. This is necessary because Display.serviceRepaints() // needs to handle its own locking. We avoid locking by making // a copy of currentDisplay -- an atomic operation -- before // testing and using it. Display d = currentDisplay; if (d != null) { d.serviceRepaints(this); } } /** * The implementation calls <code>showNotify()</code> * immediately prior to this <code>Canvas</code> 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 * <code>Canvas</code> is empty. */ protected void showNotify() { } /** * The implementation calls <code>hideNotify()</code> shortly * after the <code>Canvas</code> has been * removed from the display. * <code>Canvas</code> subclasses may override this method in * order to pause * animations, * revoke timers, etc. The default implementation of this * method in class <code>Canvas</code> is empty. */ protected void hideNotify() { } /** * Renders the <code>Canvas</code>. The application must implement * this method in * order to paint any graphics. * * <p>The <code>Graphics</code> object's clip region defines the * area of the screen * that is considered to be invalid. A correctly-written * <code>paint()</code> routine * must paint <em>every</em> pixel within this region. This is necessary * because the implementation is not required to clear the region prior to * calling <code>paint()</code> on it. Thus, failing to paint * every pixel may result * in a portion of the previous screen image remaining visible. </p> * * <p>Applications <em>must not</em> assume that * they know the underlying source of the <code>paint()</code> * call and use this * assumption * to paint only a subset of the pixels within the clip region. The * reason is * that this particular <code>paint()</code> call may have * resulted from multiple * <code>repaint()</code> * 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. </p> * * <p>Operations on this graphics object after the <code>paint() * </code>call returns are * undefined. Thus, the application <em>must not</em> cache this * <code>Graphics</code> * object for later use or use by another thread. It must only be * used within * the scope of this method. </p> * * <p>The implementation may postpone visible effects of * graphics operations until the end of the paint method.</p> * * <p> The contents of the <code>Canvas</code> are never saved if * it is hidden and then * is made visible again. Thus, shortly after * <code>showNotify()</code> is called, * <code>paint()</code> will always be called with a * <code>Graphics</code> object whose clip region * specifies the entire displayable area of the * <code>Canvas</code>. Applications * <em>must not</em> rely on any contents being preserved from a previous * occasion when the <code>Canvas</code> was current. This call to * <code>paint()</code> will not * necessarily occur before any other key or pointer * methods are called on the <code>Canvas</code>. Applications * whose repaint * recomputation is expensive may create an offscreen * <code>Image</code>, paint into it, * and then draw this image on the <code>Canvas</code> when * <code>paint()</code> is called. </p> * * <P>The application code must never call <code>paint()</code>;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -