📄 canvas.java
字号:
* of network usage. If the indicator is rendered on screen, * it must be visible when network activity occurs, even when * the <code>Canvas</code> is in full-screen mode.</P> * * @since MIDP 1.0 */public abstract class Canvas extends Displayable { /** * Constant for the <code>UP</code> game action. * * <P>Constant value <code>1</code> is set to <code>UP</code>.</P> */ public static final int UP = 1; /** * Constant for the <code>DOWN</code> game action. * * <P>Constant value <code>6</code> is set to <code>DOWN</code>.</P> */ public static final int DOWN = 6; /** * Constant for the <code>LEFT</code> game action. * * <P>Constant value <code>2</code> is set to <code>LEFT</code>.</P> */ public static final int LEFT = 2; /** * Constant for the <code>RIGHT</code> game action. * * <P>Constant value <code>5</code> is set to <code>RIGHT</code>.</P> */ public static final int RIGHT = 5; /** * Constant for the <code>FIRE</code> game action. * * <P>Constant value <code>8</code> is set to <code>FIRE</code>.</P> */ public static final int FIRE = 8; /** * Constant for the general purpose "<code>A</code>" game action. * * <P>Constant value <code>9</code> is set to <code>GAME_A</code>.</P> */ public static final int GAME_A = 9; /** * Constant for the general purpose "<code>B</code>" game action. * * <P>Constant value <code>10</code> is set to <code>GAME_B</code>.</P> */ public static final int GAME_B = 10; /** * Constant for the general purpose "<code>C</code>" game action. * * <P>Constant value <code>11</code> is set to <code>GAME_C</code>.</P> */ public static final int GAME_C = 11; /** * Constant for the general purpose "<code>D</code>" game action. * * <P>Constant value <code>12</code> is set to <code>GAME_D</code>.</P> */ public static final int GAME_D = 12; /** * keyCode for ITU-T key <code>0</code>. * * <P>Constant value <code>48</code> is set to <code>KEY_NUM0</code>.</P> */ public static final int KEY_NUM0 = 48; /** * keyCode for ITU-T key <code>1</code>. * * <P>Constant value <code>49</code> is set to <code>KEY_NUM1</code>.</P> */ public static final int KEY_NUM1 = 49; /** * keyCode for ITU-T key <code>2</code>. * * <P>Constant value <code>50</code> is set to <code>KEY_NUM2</code>.</P> */ public static final int KEY_NUM2 = 50; /** * keyCode for ITU-T key <code>3</code>. * * <P>Constant value <code>51</code> is set to <code>KEY_NUM3</code>.</P> */ public static final int KEY_NUM3 = 51; /** * keyCode for ITU-T key <code>4</code>. * * <P>Constant value <code>52</code> is set to <code>KEY_NUM4</code>.</P> */ public static final int KEY_NUM4 = 52; /** * keyCode for ITU-T key <code>5</code>. * * <P>Constant value <code>53</code> is set to <code>KEY_NUM5</code>.</P> */ public static final int KEY_NUM5 = 53; /** * keyCode for ITU-T key <code>6</code>. * * <P>Constant value <code>54</code> is set to <code>KEY_NUM6</code>.</P> */ public static final int KEY_NUM6 = 54; /** * keyCode for ITU-T key <code>7</code>. * * <P>Constant value <code>55</code> is set to <code>KEY_NUM7</code>.</P> */ public static final int KEY_NUM7 = 55; /** * keyCode for ITU-T key <code>8</code>. * * <P>Constant value <code>56</code> is set to <code>KEY_NUM8</code>.</P> */ public static final int KEY_NUM8 = 56; /** * keyCode for ITU-T key <code>9</code>. * * <P>Constant value <code>57</code> is set to <code>KEY_NUM09</code>.</P> */ public static final int KEY_NUM9 = 57; /** * keyCode for ITU-T key "star" (<code>*</code>). * * <P>Constant value <code>42</code> is set to <code>KEY_STAR</code>.</P> */ public static final int KEY_STAR = 42; /** * keyCode for ITU-T key "pound" (<code>#</code>). * * <P>Constant value <code>35</code> is set to <code>KEY_POUND</code>.</P> */ public static final int KEY_POUND = 35; /** * Constructs a new <code>Canvas</code> object. */ protected Canvas() { } /** * Used by GameCanvas to suppress Game action key events */ private boolean suppressKeyEvents; // = false /** * Checks if the <code>Canvas</code> is double buffered by the * implementation. * @return <code>true</code> if double buffered, * <code>false</code> otherwise */ public boolean isDoubleBuffered() { // SYNC NOTE: return of atomic value, no locking necessary return Display.IS_DOUBLE_BUFFERED; } /** * Checks if the platform supports pointer press and release events. * @return <code>true</code> if the device supports pointer events */ public boolean hasPointerEvents() { // SYNC NOTE: return of atomic value, no locking necessary return Display.POINTER_SUPPORTED; } /** * Checks if the platform supports pointer motion events (pointer dragged). * Applications may use this method to determine if the platform is capable * of supporting motion events. * @return <code>true</code> if the device supports pointer motion events */ public boolean hasPointerMotionEvents() { // SYNC NOTE: return of atomic value, no locking necessary return Display.MOTION_SUPPORTED; } /** * Checks if the platform can generate repeat events when key * is kept down. * @return <code>true</code> if the device supports repeat events */ public boolean hasRepeatEvents() { // SYNC NOTE: return of atomic value, no locking necessary return Display.REPEAT_SUPPORTED; } /** * Gets a key code that corresponds to the specified game action on the * device. The implementation is required to provide a mapping for every * game action, so this method will always return a valid key code for * every game action. See <a href="#gameactions">above</a> for further * discussion of game actions. There may be multiple keys associated * with the same game action; however, this method will return only one of * them. Applications should translate the key code of every key event * into a game action using {@link #getGameAction} and then interpret the * resulting game action, instead of generating a table of key codes at * using this method during initialization. * * <P>The mapping between key codes and game actions * will not change during the execution of the application.</P> * * @param gameAction the game action * @return a key code corresponding to this game action * @throws IllegalArgumentException if <code>gameAction</code> * is not a valid game action */ public int getKeyCode(int gameAction) { // SYNC NOTE: no locking necessary as we are doing a static // table lookup and getKeyCode() is implemented natively int n = Display.getKeyCode(gameAction); if (n == 0) { throw new IllegalArgumentException(); } return n; } /** * Gets an informative key string for a key. The string returned will * resemble the text physically printed on the key. This string is * suitable for displaying to the user. For example, on a device * with function keys <code>F1</code> through <code>F4</code>, * calling this method on the <code>keyCode</code> for * the <code>F1</code> key will return the string * "<code>F1</code>". A typical use for this string * will be to compose help text such as "Press * <code>F1</code> to proceed." * * <p> This method will return a non-empty string for every valid key code. * </p> * * <p> There is no direct mapping from game actions to key names. To get * the string name for a game action <code>GAME_A</code>, the * application must call </p> * * <TABLE BORDER="2"> * <TR> * <TD ROWSPAN="1" COLSPAN="1"> * <pre><code> * getKeyName(getKeyCode(GAME_A)); </code></pre> * </TD> * </TR> * </TABLE> * @param keyCode the key code being requested * @return a string name for the key * @throws IllegalArgumentException if <code>keyCode</code> * is not a valid key code */ public String getKeyName(int keyCode) { // SYNC NOTE: no locking necessary as we are doing a static // table lookup and getKeyName() is implemented natively String s = Display.getKeyName(keyCode); if (s == null) { throw new IllegalArgumentException(); } return s; } /** * Gets the game action associated with the given key code of the * device. Returns zero if no game action is associated with this key * code. See <a href="#gameactions">above</a> for further discussion of * game actions. * * <P>The mapping between key codes and game actions * will not change during the execution of the application.</P> * * @param keyCode the key code * @return the game action corresponding to this key, or * <code>0</code> if none * @throws IllegalArgumentException if <code>keyCode</code> * is not a valid key code */ public int getGameAction(int keyCode) { // SYNC NOTE: no locking necessary as we are doing a static // table lookup and getGameAction() is implemented natively int n = Display.getGameAction(keyCode); if (n == -1) { throw new IllegalArgumentException(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -