showproperties.java

来自「J2ME程序设计实例教程的源码」· Java 代码 · 共 65 行

JAVA
65
字号
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ShowProperties extends MIDlet implements CommandListener {
    private Form form;
    private Command cmdExit = new Command("退出", Command.EXIT, 1);
    
    public ShowProperties() {
        form = new Form("属性列表");
        form.addCommand(cmdExit);
        form.setCommandListener(this);
    }
    
    public void startApp() {
        //读取MIdlet属性,显示在KToolbar的控制台中。
        form.append(new StringItem("MIDlet-Name: ", 
                            getAppProperty("MIDlet-Name")));
        form.append(new StringItem("MIDlet-Version: ", 
                            getAppProperty("MIDlet-Version")));
        form.append(new StringItem("MIDlet-Vendor: ", 
                            getAppProperty("MIDlet-Vendor")));
        form.append(new StringItem("MIDlet-Jar-URL: ", 
                            getAppProperty("MIDlet-Jar-URL")));
        form.append(new StringItem("MIDlet-Jar-Size: ", 
                            getAppProperty("MIDlet-Jar-Size")));
        form.append(new StringItem("MicroEdition-Profile: ", 
                            getAppProperty("MicroEdition-Profile")));
        form.append(new StringItem("MicroEdition-Configuration: ", 
                            getAppProperty("MicroEdition-Configuration")));
        
        //读取自定义属性
        form.append(new StringItem("Cat-Tom: ", getAppProperty("Cat-Tom")));
        
        //读取平台的系统属性
        form.append(new StringItem("microedition.platform: ", 
                            System.getProperty("microedition.platform")));
        
        //编码属性
        form.append(new StringItem("microedition.encoding: ", 
                            System.getProperty("microedition.encoding")));
        form.append(new StringItem("microedition.profiles: ", 
                            System.getProperty("microedition.profiles")));
        form.append(new StringItem("microedition.configuration: ", 
                          System.getProperty("microedition.configuration")));
        
        Display d = Display.getDisplay(this);
        d.setCurrent(form);
    }
  
    public void pauseApp() {
        //
    }
  
    public void destroyApp(boolean force) {
        //
    }
    
    //
    public void commandAction(Command cmd, Displayable d) {
        if(cmd == cmdExit) {
            notifyDestroyed();
        }
    }
}

⌨️ 快捷键说明

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