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

📄 form.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        } else { // not grouped            if (oldItem != null && oldItem.isGroupable()) {                TaGLayout tag = (TaGLayout)oldItem.layouts[0];                deltaHeight = tag.delete(oldItem);            }            // possibly new item is inserted in the middle of grouped items            if (itemNum > 0 && itemNum+1 < numOfItems &&                items[itemNum-1].isGrouped(items[itemNum+1])) {                TaGLayout prevTag = (TaGLayout)items[itemNum-1].layouts[0];                TaGLayout nextTag = new TaGLayout(Screen.CONTENT_FONT);                // move all items after the inserted item to a new group                // from the group where the items before the inserted item were                for (int i = itemNum+1; i < numOfItems; i++) {                    if (items[i].layouts[0] == prevTag) {                        deltaHeight += prevTag.delete(items[i]);                        // note that we do not add to the delta height on                        // the insert since we created a new layout                        // height will be added at once when all items                        // are moved                        nextTag.insert(null, items[i]);                    } else {                        break;                    }                }                if (initLayoutDone()) {                    deltaHeight += nextTag.setWidth(Display.WIDTH);                }            }                        if (initLayoutDone()) {                deltaHeight += item.setWidth(Display.WIDTH);            }        }                item.setOwner(this);        item.setFocus(itemHadFocus);                items[itemNum] = item;                if (oldItem != null) {            oldItem.setOwner(null);        }                contentChanged(items[itemNum], 0, 0, deltaHeight);    }        /**     * Get the y coordinate location of the specified item     *     * @param item The Item to calculate the y position for     * @return int The y coordinate location of the Item     */    int getItemY(Item item) {        if (numOfItems == 1) {            return item == items[0] ? 0 : -1;        }        for (int i = 1, y = 0; i < numOfItems; i++) {            if (!items[i].isGrouped(items[i-1])) {                y += items[i-1].getHeight();            }            if (items[i] == item) {                return y;            }        }        return -1;    }    /**     * Handle a key press     *     * @param keyCode The key that was pressed     */    void keyPressed(int keyCode) {        Item curItem = null;        ItemStateListener isl = null;        synchronized (Display.LCDUILock) {            if (numOfItems == 0) {                return;            }            int gameKeyCode = Display.getGameAction(keyCode);            if (gameKeyCode == Canvas.UP ||                    gameKeyCode == Canvas.DOWN) {                super.keyPressedImpl(keyCode);            } else if (curItemIndex != -1) {                curItem = items[curItemIndex];                if ((gameKeyCode == Canvas.FIRE && curItem.select()) ||                        (curItem.keyPressed(keyCode))) {                    isl = itemStateListener;                }            }        } // synchronized        if (isl != null) {            // Protect from any unexpected application exceptions            try {                // SYNC NOTE: We lock on calloutLock around any calls                // into application code                synchronized (Display.calloutLock) {                    isl.itemStateChanged(curItem);                }            } catch (Throwable thr) {                Display.handleThrowable(thr);            }        }    }    /**     * Traverse this Form     *     * @param down     * @param top     * @param bottom     * @param height     * @param lineHeight     * @param traversingIn     * @param takesFocus     * @return int     */    static int traverse(boolean down, int top, int bottom,                        int height, int lineHeight,                         boolean traversingIn, boolean takesFocus) {                // if going down the bottom of the unit is already visible or        // if going up the top of the unit is already visible        // then we can either return 0 meaning that traversal was done        // or return -1 meaning that we should traverse to the next unit.        if ((down && (bottom >= height))  || (!down && (top <= 0))) {            return (traversingIn && takesFocus) ? 0 : -1;        }        int vpHeight = bottom - top;        int heightToEnd = down ? height - bottom : top;        // when traversing in show as much of the unit as you can        // while scrolling as little as possible        if (traversingIn) {            int s = vpHeight;            if (down && top < 0) {                s = -top;            } else if (!down && height < bottom) {                s = bottom - height;            }            if (heightToEnd < s) {                s = heightToEnd;            }            return s;        }        // if what was not displayed is shorter than the viewport height        // than scroll just by this amount        if (heightToEnd <= vpHeight) {            return heightToEnd;        }        // other wise we will show some context         // (the smallest context could be half a line)        int blockIncr = vpHeight - lineHeight/2;        if (blockIncr < lineHeight) {            blockIncr = lineHeight;        } else {            blockIncr -= (blockIncr % lineHeight);        }        return heightToEnd < blockIncr ? heightToEnd : blockIncr;    }    /**     * Traverse this Form     *     * @param gameKeyCode     * @param top     * @param bottom     * @return -1 if there is no need to scroll and      *            there is no need to repaint;     *          0 if there is no need to scroll but      *            content should be repainted; or     *          scrollHeight by which the viewPort y location to be adjusted     */    int traverse(int gameKeyCode, int top, int bottom) {        if (gameKeyCode != Canvas.UP && gameKeyCode != Canvas.DOWN) {            return -1;        }        int dir = gameKeyCode == Canvas.UP ? -1 : 1;        Item curItem = items[curItemIndex];        int itemNum = curItemIndex;        int y = curItemY;        for (int i = curItemIndex; i >= 0 && i < numOfItems; i += dir) {            boolean traversingIn = i != curItemIndex;            if (traversingIn && items[i].isGrouped(items[itemNum])) {                continue;            }                        // update y and itemNum            if (traversingIn) {                int itemHeight = items[i].getHeight();                if (dir < 0) {                    y -= itemHeight;                } else {                    y += items[itemNum].getHeight();                }                itemNum = i;            }            int vpY1 = top - y;            int vpY2 = bottom - y;            boolean allowExit = dir < 0 ? i != 0 : i != numOfItems-1;            int scrollHeight = items[i].traverse(gameKeyCode, vpY1, vpY2,                                                  traversingIn, allowExit);            if (scrollHeight >= 0) {                // traversal was done within item                if (traversingIn) {                    moveCurItem(i);                    curItemY = y;                }                return scrollHeight;            }        }        return -1;    }    /**     * Move the currently selected item to a new index     *     * @param newCurItem The index of the new location for the Item     */    private void moveCurItem(int newCurItem) {        if (!initLayoutDone()) {            return;        }        if (curItemIndex != -1 && items[curItemIndex] != null &&                items[curItemIndex].hasFocus()) {            items[curItemIndex].setFocus(false);        }        curItemIndex = newCurItem;        if (curItemIndex != -1 && items[curItemIndex].takesFocus()) {            items[curItemIndex].setFocus(true);        }    }    /**     * Signal this Form that its height has changed     *     * @param vpY     * @param vpH     * @param deltaHeight     * @return int     */    int heightChanged(int vpY, int vpH, int deltaHeight) {        vpY = super.heightChanged(vpY, vpH, deltaHeight);        if (curItemIndex != -1 && numOfItems > 1) {            // find the item that is currently at the very top            curItemY = 0;            for (int i = 1; i < numOfItems; i++) {                if (!items[i].isGrouped(items[i-1])) {                    int h = items[i-1].getHeight();                    // The following can happen only when                    // item displayed is taller that the                     // viewport area                    if (curItemY + h > vpY + vpH) {                        moveCurItem(i);                        return vpY;                    }                    curItemY += h;                }                if (curItemY >= vpY) {                    // currentItem is visible and it can take focus                    if (items[i].takesFocus()) {                        moveCurItem(i);                        return vpY;                    }                }            }            // current item is not entirely visible and it is hard to            // init focus            return initHilight(vpY, vpH);        }        return vpY;    }    /**     * Handle a typed key from a keyboard     *     * @param c The char typed from the keyboard     */    void keyTyped(char c) {        synchronized (Display.LCDUILock) {            if (curItemIndex != -1) {                items[curItemIndex].keyTyped(c);            }        }    }    /**      * This method should be used by items of this form      * when they need to notify itemStateListener of its changed state     *     * @param item The Item which state was changed     * @param isl The itemStateListener to notify of the change     */    static final void itemStateChanged(Item item, ItemStateListener isl) {        if (isl == null || item == null) {            return;        }        // Protect from any unexpected application exceptions        try {            // SYNC NOTE: We lock on calloutLock around any calls            // into application code            synchronized (Display.calloutLock) {                isl.itemStateChanged(item);            }        } catch (Throwable thr) {            Display.handleThrowable(thr);        }    }}

⌨️ 快捷键说明

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