▼MIDP2.0メモ▼
端末制御を行う


端末制御を行うプログラム。

 


プログラム
PhoneSystemEx.java
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

//端末制御を行う(本体)
public class PhoneSystemEx extends MIDlet {
    static MIDlet  midlet;
    static Display display;

    //コンストラクタ
    public PhoneSystemEx() {
        midlet =this;
        display=Display.getDisplay(this);
        display.setCurrent(new PhoneSystemForm());
    }

    //アプリの開始
    public void startApp() {
    }

    //アプリの一時停止
    public void pauseApp() {
    }

    //アプリの終了
    public void destroyApp(boolean flag) {
    }
}


PhoneSystemForm.java
import javax.microedition.lcdui.*;
import javax.microedition.media.*;

//端末制御を行う(フォーム)
class PhoneSystemForm extends Form
    implements ItemCommandListener {

    //コンストラクタ
    public PhoneSystemForm(){
        super("PhoneSystemyEx");

        //メモリを調べる
        Runtime run=Runtime.getRuntime();
        addMemoryItem("Free Memory",run.freeMemory());
        addMemoryItem("Total Memory",run.totalMemory());

         //システムプロパティを調べる
        addPropertyItem("microedition.configuration");
        addPropertyItem("microedition.profiles");
        addPropertyItem("microedition.locale");
        addPropertyItem("microedition.encoding");
        addPropertyItem("microedition.io.file.FileConnection.version");
        addPropertyItem("microedition.pim.version");
        addPropertyItem("file.separator");

        //ボタンの追加
        addButton("バックライト",0);
        addButton("バイブレーション",1);
        addButton("URLジャンプボタン",2);
    }

    //メモリアイテムの追加
    void addMemoryItem(String key,long value) {
        StringItem item=new StringItem("",key+":"+value);
        item.setLayout(Item.LAYOUT_2|Item.LAYOUT_NEWLINE_AFTER);
        append(item);
    }

    //プロパティアイテムの追加
    void addPropertyItem(String key) {
        StringItem item=new StringItem("",key+":"+
            System.getProperty(key));
        item.setLayout(Item.LAYOUT_2|Item.LAYOUT_NEWLINE_AFTER);
        append(item);
    }

    //ボタンの追加
    void addButton(String label,int priority) {
        StringItem button=new StringItem("",label,Item.BUTTON);
        button.setLayout(Item.LAYOUT_2|Item.LAYOUT_NEWLINE_AFTER);
        button.setDefaultCommand(new Command("",Command.SCREEN,priority));
        button.setItemCommandListener(this);
        append(button);
    }

    //アイテムイベント
    public void commandAction(Command c,Item item)  {
        if (c.getPriority()==0) {
            //バックライトのフラッシュ
            PhoneSystemEx.display.flashBacklight(3000);
        }
        if (c.getPriority()==1) {
            //バイブレーション
            PhoneSystemEx.display.vibrate(3000);
        }
        if (c.getPriority()==2) {
            //URLジャンプ
            try {
                PhoneSystemEx.midlet.platformRequest(
                    "http://www.google.co.jp/");
            } catch (Exception e) {
            }
        }
    }
}



−戻る−