listtest2.java

来自「《精彩的手机UI例程.zip》是很好的手机编辑软件」· Java 代码 · 共 57 行

JAVA
57
字号

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

public class ListTest2 extends MIDlet implements CommandListener{
	private List list;
	private Command exitCommand = new Command("Exit", Command.BACK, 1);
	private String[] options={"Option A","Option B","Option C"};	
	private Display display;
	
    public ListTest2() {
        //create an implicit list
	list= new List("Implicit-choice list",List.IMPLICIT,
                                options, null);
        try {
            Image img0= Image.createImage("/open.png");
            list.set(0,"Open",img0);
            Image img1= Image.createImage("/smallDuke.png");
            list.set(1,"Duke",img1);
        }catch(Exception e){
            System.out.println("Error: "+e.getMessage());
        }
        //Add commands 
	list.addCommand(exitCommand);
	list.setCommandListener(this);

	display=Display.getDisplay(this);
    }
    public void startApp() throws MIDletStateChangeException {
        display.setCurrent(list);
    }

    /**
     * Pause the MIDlet
     */
    public void pauseApp() {
    }

    /**
     * Called by the framework before the application is unloaded
     */
    public void destroyApp(boolean unconditional) {
        //clear everything
	list=null;
	exitCommand = null;
	display=null;
    }

    public void commandAction(Command c, Displayable d) {
        if(c==exitCommand) {
            destroyApp(true);
	    notifyDestroyed();
	}
    }
}

⌨️ 快捷键说明

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