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

📄 form.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    TaGLayout tag = (TaGLayout)items[itemNum-1].layouts[0];                    deletedHeight -= items[itemNum+1].getHeight();                    for (int i = itemNum+1; i < numOfItems; i++) {                        if (items[i].isGrouped(items[itemNum+1])) {                            deletedHeight += tag.insert(null, items[i]);                          } else {                            break;                        }                    }                }            }            if (numOfItems > 1 && curItemIndex == itemNum) {                if (curItemIndex > 0) {                    moveCurItem(curItemIndex-1);                } else {                    moveCurItem(curItemIndex+1);                }            }            if (curItemIndex >= itemNum) {                curItemIndex--;            }            deletedItem.setOwner(null);            numOfItems--;            if (itemNum < numOfItems) {                System.arraycopy(items, itemNum + 1, items, itemNum,                                 numOfItems - itemNum);            }            // Delete reference to the last item             // that was left after array copy            items[numOfItems] = null;            contentChanged(null, 0, 0, deletedHeight);        } // synchronized    }    /**     * <p> Sets the item referenced by itemNum to the specified item,     * replacing the previous item. The previous item is removed     * from this Form.     * The itemNum parameter must be      * within the range [0..size()-1], inclusive. </p>     *     * The end result is equal to<P>     * <code>insert(n, item); delete(n+1);</code><br>     * although the implementation may optimize the repainting     * and usage of the array that stores the items. <P>     *     * @param itemNum the index of the item to be replaced     * @param item the new item to be placed in the Form     *     * @throws IndexOutOfBoundsException if itemNum is invalid     * @throws IllegalStateException if the item is already owned by     * a container     * @throws NullPointerException if item is null     */    public void set(int itemNum, Item item) {        synchronized (Display.LCDUILock) {            // NullPointerException will be thrown            // by item.getOwner() if item == null            if (item.getOwner() != null) {                throw new IllegalStateException();            }            if (itemNum < 0 || itemNum >= numOfItems) {                throw new IndexOutOfBoundsException();            }            setImpl(itemNum, item);        }    }         /**     * <p> Gets the item at given position.  The contents of the Form are left      * unchanged.     * The itemNum parameter must be      * within the range [0..size()-1], inclusive. </p>     *     * @param itemNum the index of item     *     * @return the item at the given position     *     * @throws IndexOutOfBoundsException if itemNum is invalid     */    public Item get(int itemNum) {        synchronized (Display.LCDUILock) {            if (itemNum < 0 || itemNum >= numOfItems) {                throw new IndexOutOfBoundsException();            }            return items[itemNum];        }    }    /**     * Sets the ItemStateListener for the Form, replacing any previous     * ItemStateListener. If iListener is null, simply removes the previous     * ItemStateListener.     * @param iListener the new listener, or null to remove it     */    public void setItemStateListener(ItemStateListener iListener) {        synchronized (Display.LCDUILock) {            itemStateListener = iListener;        }    }    /**     * Gets the number of items in the Form.     * @return the number of items     */    public int size() {        // SYNC NOTE: return of atomic value, no locking necessary        return numOfItems;    }    /**     * Paint this Form's content     *     * @param g The Graphics object to paint to     */    void paintContent(Graphics g) {        int clipY1 = g.getClipY();        int clipY2 = clipY1 + g.getClipHeight();        int translatedY = 0;        Item prevItem = null;        for (int i = 0; i < numOfItems && translatedY < clipY2; i++) {            if (!items[i].isGrouped(prevItem)) {                int h = items[i].getHeight();                if (translatedY + h >= clipY1) {                    items[i].paint(g);                }                translatedY += h;                g.translate(0, h);                prevItem = items[i];            }        }        // Form content is shorter than the clip;        // fill the remaining area with erase color        // Graphics was already translated by translatedY.        // That is why we start painting from 0.        if (translatedY < clipY2) {            g.setColor(Display.ERASE_COLOR);            g.fillRect(g.getClipX(), 0,                        g.getClipWidth(), clipY2 - translatedY);        }    }    /**     * Layout this Form's content     *     * @param w The width of the Display     * @param h The height of the Display     * @return int The height required to fully display this Form     */    int layoutContent(int w, int h) {        if (numOfItems == 0) {            return 0;        }        int height = items[0].setWidth(w);        for (int i = 1; i < numOfItems; i++) {            if (!items[i].isGrouped(items[i-1])) {                height += items[i].setWidth(w);            }        }        return height;    }    /**     * Initializes hilight when form is shown.     * @param vpY y coordinate of viewport location     * @param vpH viewport height     * @return new y coordinate of viewport location     *         child (all items) coordinate system     */    int initHilight(int vpY, int vpH) {        if (numOfItems == 0) {            return 0;        }        // Last time that Form was displayed an item from this form        // had focus; To init focus to a different item we have        // to set focus to be false on the current one.        if (curItemIndex != -1 && items[curItemIndex].hasFocus()) {            items[curItemIndex].setFocus(false);        }        curItemIndex = curItemY = 0;        // if first item can take focus and it is shorter than the        // viewPort height and it is not grouped with the last item        // focus should be initialized to some other item.        if (!items[0].takesFocus() &&             items[0].getHeight() < vpH &&            !items[0].isGrouped(items[numOfItems-1])) {            for (int i = 1; i < numOfItems; i++) {                if (!items[i].isGrouped(items[0])) {                    curItemIndex = i;                    curItemY = items[i-1].getHeight();                    break;                }            }        }        if (items[curItemIndex].takesFocus()) {             items[curItemIndex].setFocus(true);            items[curItemIndex].initHilight(vpY-curItemY, vpH);        }        return 0;    }    /**     * Retrieve the ItemStateListener for this Form.     * NOTE: calls to this method should only occur from within     * a lock on LCDUILock.     *     * @return ItemStateListener The ItemStateListener of this Form,     *                           null if there isn't one set     */    ItemStateListener getItemStateListener() {        return itemStateListener;    }    /**     * Insert an Item into this Form     *     * @param itemNum The index into the Item array to insert this Item     * @param item The Item to insert     * @return int The index at which the newly inserted Item can be found     */    private int insertImpl(int itemNum, Item item) {        boolean forceFocus = false;        if (items.length == numOfItems) {           Item newItems[] = new Item[numOfItems + GROW_SIZE];            System.arraycopy(items, 0, newItems, 0, itemNum);            System.arraycopy(items, itemNum, newItems, itemNum + 1,                             numOfItems - itemNum);            items = newItems;        } else {            System.arraycopy(items, itemNum, items, itemNum + 1,                             numOfItems - itemNum);        }        numOfItems++;        if (initLayoutDone()) {            if (curItemIndex == -1) {                curItemIndex = 0;		// This is the first item added to a form; give it focus		forceFocus = true;            }            if (curItemIndex > itemNum) {                curItemIndex++;            }        }        items[itemNum] = null;        setImpl(itemNum, item);	if (forceFocus && items[curItemIndex].takesFocus()) {	    items[curItemIndex].setFocus(true);	}        return itemNum;    }    /**     * Set a specific Item index to be a new Item     *     * @param itemNum The Item index to change     * @param item The new Item to set     */    private void setImpl(int itemNum, Item item) {        int deltaHeight = 0;        boolean itemHadFocus = false;        Item oldItem = items[itemNum];        // delete oldItem height        if (oldItem != null) {            if (initLayoutDone()) {                deltaHeight = -oldItem.getHeight();            }            itemHadFocus = oldItem.hasFocus();        }        // Set owner, layout and focus        if (item.isGroupable()) {            if (oldItem != null && oldItem.isGroupable()) {                TaGLayout tag = (TaGLayout)oldItem.layouts[0];                deltaHeight = tag.set(oldItem, item);                // try merge with a tag layout before next item            } else if (itemNum+1 < numOfItems &&                       items[itemNum+1].isGroupable()) {                TaGLayout tag = (TaGLayout)items[itemNum+1].layouts[0];                deltaHeight = tag.insert(items[itemNum+1], item);                if (curItemIndex == itemNum+1 && tag.get(item) == 0) {                    curItemIndex = itemNum;                }                // try merge with a tag layout after previous item            } else if (itemNum > 0 && items[itemNum-1].isGroupable()) {                TaGLayout tag = (TaGLayout)items[itemNum-1].layouts[0];                deltaHeight = tag.insert(null, item);                if (curItemIndex == itemNum-1 && tag.getSize() > 2)  {                    curItemIndex = itemNum;                }                // item is surrounded by items that are not                // StringItems or ImageItems                            } else {                                TaGLayout tag = new TaGLayout(Screen.CONTENT_FONT);                tag.insert(null, item);                if (initLayoutDone()) {                    deltaHeight = tag.setWidth(Display.WIDTH);                }            }            

⌨️ 快捷键说明

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