⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 display.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    /**     * set the current horizontal scroll position and proportion.     * @param scrollPosition horizontal scroll position.     * @param scrollProportion horizontal scroll proportion.     */    native void setHorizontalScroll(int scrollPosition, int scrollProportion);    /**     * get the current vertical scroll position.     * @return the vertical scroll position.     */    int getVerticalScrollPosition() {        // SYNC NOTE: No need to lock here because 'current'        // can only be null once, at startup, so we don't care        // if 'current' changes values, just that it isn't null        if (current != null) {            return current.getVerticalScrollPosition();        } else {            return 0;        }    }    /**     * get the current vertical scroll proportion.     * @return the vertical scroll proportion.     */    int getVerticalScrollProportion() {        // SYNC NOTE: No need to lock here because 'current'        // can only be null once, at startup, so we don't care        // if 'current' changes values, just that it isn't null         if (current != null) {            return current.getVerticalScrollProportion();        } else {            return 100;        }    }    /**     * set the current vertical scroll position and proportion.     * @param scrollPosition vertical scroll position.     * @param scrollProportion vertical scroll proportion.     */    native void setVerticalScroll(int scrollPosition, int scrollProportion);    /**     * set the input, mode.     * @param mode type of input to accept.     */    native void setInputMode(int mode);    /**     * Return the game action associated with the given key code on     * the device.  keyCode must refer to a key that is mapped as a     * game key on the device The game action of the key is returned.     * The return value will be 0 if the key is not mapped to a game     * action or not present on the device.     *     * @param keyCode the key code     * @return the corresponding game action (UP, DOWN, LEFT, RIGHT, FIRE, etc.)     */    static int getGameAction(int keyCode) {        return eventHandler.getGameAction(keyCode);    }    /**     * returns 0 if keyCode is not a system key.  Otherwise, returns     * one of the EventHandler.SYSTEM_KEY_ constants.     * @param keyCode get the system equivalent key.     * @return translated system key or zero if it is not a system key.     */    static int getSystemKey(int keyCode) {        return eventHandler.getSystemKey(keyCode);    }    /**     * Gets an informative key string for a key. The string returned     * should resemble the text physically printed on the key. For     * example, on a device with function keys 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."     *     * <p>There is no direct mapping from game actions to key     * names. To get the string name for a game action, the     * application must call     *     * <p><code>getKeyName(getKeyCode(GAME_A))</code>     * @param keyCode the key code being requested     * @return a string name for the key, or null if no name is available      */    static String getKeyName(int keyCode) {        return eventHandler.getKeyName(keyCode);    }    /** required so that Command menus can be updated while owner is visible */    void updateCommandSet() {        eventHandler.updateCommandSet(current.getCommands(),                                      current.getCommandCount());    }    /**     * is the current display visible.     * @param d displayble instance to check, if current and visible.     * @return true, if the Display is visible and the object is current.     */    boolean isShown(Displayable d) {        // SYNC NOTE: calls to isShown() should be synchronized on        // the LCDUILock.        return hasForeground            && !paintSuspended            && (current == d);    }    /**     * This is a utility method used to handle any Throwables     * caught while calling application code. The default     * implementation will simply call printStackTrace() on     * the Throwable. Note, the parameter must be non-null or     * this method will generate a NullPointerException.     *     * @param t The Throwable caught during the call into     *          application code.     */    static void handleThrowable(Throwable t) {        t.printStackTrace();    }    /** this is nested inside Display so that it can see the private fields */    class DisplayAccessor implements DisplayAccess {        /**         * display painting.         */        public void suspendPainting() {            Displayable currentCopy = null;            synchronized (Display.LCDUILock) {                paintSuspended = true;                currentCopy = current;            }            // SYNC NOTE: The implementation of Displayable.hideNotify()            // will obtain the LCDUILock around the internal call to            // hideNotifyImpl(), then release LCDUILock and obtain            // calloutLock and call (potentially) into the application's            // hideNotify() method. Displayable also protects the application            // call in a try/catch            if (currentCopy != null) {                currentCopy.hideNotify(Display.this);            }            // We want to re-set the scroll indicators when we suspend so            // that the overtaking screen doesn't have to do it            setHorizontalScroll(0, 100);            setVerticalScroll(0, 100);        }        /**         * resume paininting , if doing repaint operations.         */        public void resumePainting() {            registerNewCurrent(current, false);        }        /**         * Called from the event delivery system when a command is seen.         * @param id The id of the command for listener notification         *           (as is returned by Command.getID())         */        public void commandAction(int id) {            Command commands[];            CommandListener listener;            Command c = null;            Displayable currentCopy = null;            synchronized (LCDUILock) {                if (current == null) {                    return;                }                if ((commands = current.getCommands()) == null) {                    return;                }                if ((listener = current.getCommandListener()) == null) {                    return;                }                for (int i = 0; i < commands.length; i++) {                    if (commands[i].getID() == id) {                        c = commands[i];                        break;                    }                }                if (c == null) {                    // This means that in the time it took to receive the                    // Command event, that Command has since been removed                    // from the current Displayable, or the Displayable from                    // which that Command originated is no longer current                    return;                }                currentCopy = current;            } // synchronized            // Protect from any unexpected application exceptions            try {                // SYNC NOTE: We release the lock on LCDUILock and acquire                // calloutLock before calling into application code                synchronized (calloutLock) {                    listener.commandAction(c, currentCopy);                }            } catch (Throwable thr) {                handleThrowable(thr);            }        } // commandAction        /**         * Called from the event delivery loop when a pointer event is seen.         * @param type kind of pointer event         * @param x x-coordinate of pointer event         * @param y y-coordinate of pointer event         */        public void pointerEvent(int type, int x, int y) {            Displayable currentCopy = null;            int eventType = -1;            synchronized (LCDUILock) {                if (current == null) {                    return;                }                currentCopy = current;                switch (type) {                    case EventHandler.PRESSED:                        sawPointerPress = true;                        eventType = 0;                        break;                    case EventHandler.RELEASED:                        if (sawPointerPress) {                            eventType = 1;                        }                        break;                    case EventHandler.DRAGGED:                        if (sawPointerPress) {                            eventType = 2;                         }                        break;                }            } // synchronized            // Nothing else to do            if (eventType == -1) {                return;            }            // Protect from any unexpected application exceptions            try {                // SYNC NOTE: Its possible we are calling into application                // code, so we carefully copy 'current' above (while locked),                // release the lock on LCDUILock and acquire calloutLock                // before making the call                synchronized (calloutLock) {                    if (eventType == 0) {                        currentCopy.pointerPressed(x, y);                    } else if (eventType == 1) {                        currentCopy.pointerReleased(x, y);                    } else {                        currentCopy.pointerDragged(x, y);                    }                }            } catch (Throwable thr) {                handleThrowable(thr);            }        } // pointerEvent()        /**         * Called from the event delivery loop when a key event is seen.         * @param type kind of key event - pressed, release, repeated, typed         * @param keyCode key code of entered key         */        public void keyEvent(int type, int keyCode) {            Displayable currentCopy = null;            int eventType = -1;            synchronized (LCDUILock) {                if (current == null) {                    return;                }                currentCopy = current;                switch (type) {                    case EventHandler.PRESSED:                        sawKeyPress = true;                        eventType = 0;                        break;                    case EventHandler.RELEASED:                        if (sawKeyPress) {                            eventType = 1;                        }                        break;                    case EventHandler.REPEATED:                        if (sawKeyPress) {                            eventType = 2;                        }                        break;                    case EventHandler.TYPED:                        eventType = 3;                }            } // synchronized            // Nothing else to do            if (eventType == -1) {                return;            }            // Protect from any unexpected application exceptions            try {                // SYNC NOTE: Its possible we are calling into application                // code, so we carefully copy 'current' above (while locked)                // release the lock on LCDUILock and acquire calloutLock                // before making the call                synchronized (calloutLock) {                    if (eventType == 0) {                        currentCopy.keyPressed(keyCode);                    } else if (eventType == 1) {                        currentCopy.keyReleased(keyCode);                    } else if (eventType == 2) {                        currentCopy.keyRepeated(keyCode);                    } else {                        currentCopy.keyTyped((char) keyCode);                    }                }            } catch (Throwable thr) {                handleThrowable(thr);            }        } // keyEvent()        /**         * Called from the event delivery loop when a timer event is seen.         * @param type kind of timer event - serially, repaint, screen         */        public void timerEvent(int type) {            if (type == EventHandler.CALLED_SERIALLY) {                serviceRepaints();                getCallSerially();            } else if (type == EventHandler.REPAINT) {                serviceRepaints();            } else if (type == EventHandler.SCREEN) {                Displayable newCurrent = null;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -