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

📄 screen.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            return -1;        }        // calculate the amount to scroll a screenful,        // with the minimum being a line of content        int blockIncr = (((bottom - top + (CONTENT_HEIGHT / 2)) /                           CONTENT_HEIGHT) - 1) * CONTENT_HEIGHT;        if (blockIncr < CONTENT_HEIGHT) {            blockIncr = CONTENT_HEIGHT;        }        if ((dir == Canvas.DOWN) && ((childHeight - bottom) < blockIncr)) {            return (childHeight - bottom);        } else if ((dir == Canvas.UP) && (top < blockIncr)) {            return top;        }        return blockIncr;    }    /**     * Handle a key pressed event     *     * @param keyCode The key that was pressed     */    void keyPressed(int keyCode) {        synchronized (Display.LCDUILock) {            keyPressedImpl(keyCode);        } // synchronized    }    /**     * Handle a key repeated event     *     * @param keyCode The key that was pressed     */    void keyRepeated(int keyCode) {        // SYNC NOTE: Locking handled by keyPressed()        keyPressed(keyCode);    }    // SYNC NOTE: These three empty methods should include a    // synchronized implementation (similar to keyPressedImpl())    // when/if they are needed    /**     * Handle a pointer pressed event     *     * @param x The x coordinate of the press     * @param y The y coordinate of the press     */    void pointerPressedImpl(int x, int y) { }    /**     * Handle a pointer released event     *     * @param x The x coordinate of the release     * @param y The y coordinate of the release     */    void pointerReleasedImpl(int x, int y) { }    /**     * Handle a pointer dragged event     *     * @param x The x coordinate of the drag     * @param y The y coordinate of the drag     */    void pointerDraggedImpl(int x, int y) { }    /**     * This method is used to determine if that screen instance     * is used as an edit screen for the screen passed in.     *     * @param d The Displayable to check     * @return boolean True, if this Screen is the "edit" screen     *                  for the Displayable     */    boolean isEditScreen(Displayable d) {        return false;    }    /**     * Set the content rectangle for this Screen     *     * @param rect An array holding the x,y,width,height     *              values of the rectangle     */    void getContentRect(int rect[]) {        if (rect != null && rect.length >= 4) {            rect[0] = globalViewPortX;            rect[1] = globalViewPortY;            rect[2] = viewPortWidth;            rect[3] = viewPortHeight;            if (hasBorder) {                rect[0] -= 2;                rect[1] -= 2;                rect[2] += 4;                rect[3] += 4;            }        }    }    /**     * Handle a key pressed event     *     * @param keyCode The key that was pressed     */    void keyPressedImpl(int keyCode) {        int gameKeyCode = Display.getGameAction(keyCode);        switch (gameKeyCode) {            case Canvas.UP:            case Canvas.DOWN:            case Canvas.LEFT:            case Canvas.RIGHT:                int scrollHeight = traverse(gameKeyCode, viewPortY,                                            viewPortY + viewPortHeight);                // there is no need to scroll and                // there is no need to repaint content                if (scrollHeight < 0) {                    return;                }                if (scrollHeight > 0) {                    if (gameKeyCode == Canvas.UP ||                            gameKeyCode == Canvas.LEFT) {                        viewPortY -= scrollHeight;                    } else if (gameKeyCode == Canvas.DOWN ||                            gameKeyCode == Canvas.RIGHT) {                        viewPortY += scrollHeight;                    }                }                // there is a need to repaint content                repaintContent();                setVerticalScroll();                break;        }    }    /**     * Handle a key repeated event     *     * @param keyCode The key that was pressed     */    void keyRepeatedImpl(int keyCode) {        keyPressedImpl(keyCode);    }    // SYNC NOTE: These two empty methods should include a    // synchronized implementation (similar to keyPressedImpl())    // when/if they are needed    /**     * Handle a key released event from the keyboard     *     * @param keyCode The key that was released     */    void keyReleasedImpl(int keyCode) { }    /**     * Handle a key typed event from the keyboard     *     * @param keyCode The key that was typed     */    void keyTypedImpl(int keyCode) { }    /**     * Notify this Screen it is being hidden     *     * @param d The Display hiding this Screen     */    void hideNotifyImpl(Display d) {        super.hideNotifyImpl(d);        if (!visible) {            return;        }        visible = false;        stopTicker();    }    /**     * Notify this Screen it is being shown on the display     *     * @param d The Display showing this Screen     */    void showNotifyImpl(Display d) {        super.showNotifyImpl(d);        if (visible) {            return;        }        if (layoutDoneOnce) {            Displayable currentCopy = d.getCurrent();            // We only want to initialize the highlight if we are            // not returning from another screen and we are not            // returning from an editor            if (currentCopy != this && (currentCopy instanceof Screen) &&                    !((Screen)currentCopy).isEditScreen(this)) {                viewPortY = initHilight(viewPortY, viewPortHeight);            }        } else {            doLayout();        }        visible = true;        startTicker();        repaint(0, 0, Display.WIDTH, Display.HEIGHT);        setVerticalScroll();    }    /** The image for this Screen */    private static final Image TITLE_IMG;    static {        /** The data to construct the image for this Screen */        byte title_data[] = {            (byte)0x89, (byte)0x50, (byte)0x4e, (byte)0x47,            (byte)0x0d, (byte)0x0a, (byte)0x1a, (byte)0x0a,            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0d,            (byte)0x49, (byte)0x48, (byte)0x44, (byte)0x52,            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x60,            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02,            (byte)0x02, (byte)0x03, (byte)0x00, (byte)0x00,            (byte)0x00, (byte)0xda, (byte)0xca, (byte)0x31,            (byte)0xfa, (byte)0x00, (byte)0x00, (byte)0x00,            (byte)0x06, (byte)0x50, (byte)0x4c, (byte)0x54,            (byte)0x45, (byte)0xbb, (byte)0xbb, (byte)0xbb,            (byte)0x6a, (byte)0x6a, (byte)0x6a, (byte)0x0f,            (byte)0x3b, (byte)0xef, (byte)0x7a, (byte)0x00,            (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x49,            (byte)0x44, (byte)0x41, (byte)0x54, (byte)0x78,            (byte)0xda, (byte)0x63, (byte)0x60, (byte)0xc0,            (byte)0x01, (byte)0x18, (byte)0x43, (byte)0x71,            (byte)0x48, (byte)0x00, (byte)0x00, (byte)0x08,            (byte)0x43, (byte)0x00, (byte)0x57, (byte)0xe8,            (byte)0x2f, (byte)0x93, (byte)0x38, (byte)0x00,            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x49,            (byte)0x45, (byte)0x4e, (byte)0x44, (byte)0xae,            (byte)0x42, (byte)0x60, (byte)0x82,        };        TITLE_IMG = Image.createImage(title_data, 0, title_data.length);        tickerTimer = new Timer();        // NOTE: The width of the default TITLE_IMG is        // 96 pixels and the height is 2 pixels    }    /**     * A special helper class to repaint the Ticker of this Screen     * if one exists     */    private class TickerPainter extends TimerTask {        /**         * Repaint the ticker area of this Screen         */        public final void run() {            synchronized (Display.LCDUILock) {                // Repaint with a clip of just the text message                Screen.this.repaint(0, 2, Display.WIDTH, CONTENT_HEIGHT);            }        }    }    /**     * Start the ticker running.     * Here we ensure that a tickerPainter can only ever be scheduled     * if the Screen is visible and the ticker is visible. The visibility     * of the ticker (tickerIsVisible) is only determined in doLayout()     */    private void startTicker() {        if (visible && tickerIsVisible) {            tickerPainter = new TickerPainter();            tickerTimer.schedule(tickerPainter, 0, Ticker.TICK_RATE);        }    }    /**     * Stop the ticker from running     * Here we only have to check for the existence of a tickerPainter     */    private void stopTicker() {        if (tickerPainter != null) {            tickerPainter.cancel();            tickerPainter = null;        }    }    /**     * Get the title of this Screen     *     * @return String The title of this Screen     */    private String getTitleImpl() {        return (screenTitle == null ?            null : ((StringLayout)screenTitle).getString());    }}

⌨️ 快捷键说明

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