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

📄 listcontrol3.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 ListControl3
    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 final static Command okCommand =
    	new Command("Ok",Command.OK,1);
    private Display display;
    private List mainList;
    private TextBox tb;
    
    
    public ListControl3() {
        display = Display.getDisplay(this);
        tb = new TextBox("List Example","List",100,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("Choose textbox", Choice.MULTIPLE, stringArray, 
                                imageArray);
            mainList.addCommand(exitCommand);
            mainList.addCommand(okCommand);
            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 == okCommand) {
                if (d.equals(mainList)) {
                	String[] stringTextbox = {"Selected 1","Selected 2","Selected 3"};
                	boolean[] selectedArray= new boolean[3];
                	mainList.getSelectedFlags(selectedArray);
                	int i = 0;
                	String str = "";
                	for (i=0;i<3;i++)
                		if(selectedArray[i]==true){
                			str = str + stringTextbox[i] + "\n";
                		}
                	tb.setString(str);
        			display.setCurrent(tb);
                			
                }
            }
        } 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 + -