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

📄 listcontrol2.java

📁 《精通JAVA手机游戏与应用程序设计》随书光盘
💻 JAVA
字号:

import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;


/**
 * 单选列表框的处理
 * The MIDlet demonstrates the different types of list supported by MIDP-2.0:
 *      EXCLUSIVE - a choice having exactly one element selected at time.
 *      IMPLICIT  - a choice in which the currently focused element is
 *                  selected when a Command is initiated.
 *      MULTIPLE  - a choice that can have arbitrary number of elements
 *                  selected at a time.
 *
 * @version 2.0
 */


public class ListControl2
    extends MIDlet
    implements CommandListener {
    private final static Command exitCommand =
	    new Command("Exit", Command.EXIT, 1);
    private final static Command backCommand =
	    new Command("Back", Command.BACK, 1);
    private Display display;
    private List mainList;
    private TextBox tb;
    
    
    public ListControl2() {
        display = Display.getDisplay(this);
        tb = new TextBox("List Example","List",15,0);
        tb.addCommand(exitCommand);
        tb.addCommand(backCommand);
        tb.setCommandListener(this);
        // these are the strings for the choices.
        
    }

    protected void startApp() {
      
            // these are the images and strings for the choices.
            Image[] imageArray = null;
    
            try {
                // load the duke image to place in the image array
                Image icon = Image.createImage("/Icon.png");
    
    
                // these are the images and strings for the choices.
                imageArray = new Image[] {
                    icon, 
                    icon, 
                    icon
                };
            } catch (java.io.IOException err) {
                // ignore the image loading failure the application can recover.
            	System.out.print("load failed ...");
            	imageArray = null;
            }
    
            String[] stringArray = {
                "Textbox A", 
                "Textbox B", 
                "Textbox C"
            };
            mainList = new List("List Example", Choice.IMPLICIT, stringArray, 
                                imageArray);
            mainList.addCommand(exitCommand);
            mainList.setCommandListener(this);
            display.setCurrent(mainList);
           
        }
    

    protected void destroyApp(boolean unconditional) {
    }

    protected void pauseApp() {
    }

    public void commandAction(Command c, Displayable d) {    
        if (d.equals(mainList)) {
            // in the main list
            if (c == List.SELECT_COMMAND) {
                if (d.equals(mainList)) {
                    switch (((List)d).getSelectedIndex()) {
                        case 0:
                        	tb.setString("Textbox A");
                            display.setCurrent(tb);
                            break;

                        case 1:
                        	tb.setString("Textbox B");
                            display.setCurrent(tb);

                            break;

                        case 2:
                        	tb.setString("Textbox C");
                            display.setCurrent(tb);

                            break;
                    }
                }
            }
        } else {
            // in one of the sub-lists
            if (c == backCommand) {
                display.setCurrent(mainList);
            }
        }

        if (c == exitCommand) {
            destroyApp(false);
            notifyDestroyed();
        }
    }
}

⌨️ 快捷键说明

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