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

📄 listscreen.java

📁 j2me下的1套UI框架.包含j2me开发中会应用的各种低级组件
💻 JAVA
字号:
package com.jmobilecore.ui.core;

import java.util.Enumeration;

/**
 * A <code>ListScreen</code> is object inherited from <code>ScreenCanvas</code>
 * which allows select item from the list of items.
 * Each item in the list must belong to the <code>ListComponent</code>
 * class. It can be an instance of <code>ListComponent</code> or subclasses.
 *
 * @author Greg Gridin
 */
public class ListScreen extends ScreenCanvas {

    /**
     * Constructs a new list with the specified title.
     * Soft keys can be added later
     * @param  title the list's title (on screen's top)
     */
    public ListScreen(Label title) {

        super(title);
    }

    /**
     * Creates a new <code>ListScreen</code> instance with specified
     * container for soft keys
     *
     * @param title      Title for current screen
     * @param softKeyBar Container for soft keys for current screen
     */
    public ListScreen(Label title, SoftKeyBar softKeyBar) {

        super(title, softKeyBar);
    }
    /**
     * Constructs a new list with the specified title and softkeys.
     * @param  title the list's title (on screen's top)
     * @param  leftAction
     * @param  rightAction
     */
    public ListScreen(Label title, SoftKey leftAction, SoftKey rightAction) {

        super(title);
        softKeyBar.setSoftKey(leftAction, SoftKey.LEFT);
        softKeyBar.setSoftKey(rightAction, SoftKey.RIGHT);
    }

    /**
     * Gets the selected item on this list form.
     *
     * @return the selected item on the list form, or null if no item is selected
     */
    public ListComponent getFocusedComponent() {

        if (focusedIndex<0 || focusedIndex>=components.size()) return null;
        return (ListComponent) components.elementAt(focusedIndex);
    }

    /**
     * Gets the selected item on this list form.
     *
     * @return the selected item on the list form, or null if no item is selected
     */
    public int getFocusedIndex() {

        return focusedIndex;
    }

    /**
     * Processes a press of a key.
     * @param       keyCode   the pressed key
     */
    public void keyPressed(int keyCode) {
        int index = 0;
        for (Enumeration e = components.elements(); e.hasMoreElements(); index++) {
            Object obj = e.nextElement();
            if (obj instanceof ListComponent) {
                if (((ListComponent) obj).getShortcut()==keyCode) {
                    changeFocus(index);
                    super.keyPressed(PlatformCanvas.KEY_SOFT_RIGHT);
                    return;
                }
            }
        }
        if (keyCode == KEY_UP) {
            if (getPreviousFocusable() == -1 && (this.getScrollDirections() & SCROLL_UP) == 0) {
                changeFocus(getLastFocusable());
                return;
            }
        }
        if (keyCode == KEY_DOWN) {
            if (getNextFocusable() == -1 && (this.getScrollDirections() & SCROLL_DOWN) == 0) {
                changeFocus(getFirstFocusable());
                return;
            }
        }

        super.keyPressed(keyCode);
    }

} // class ListScreen

⌨️ 快捷键说明

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