▼MIDP2.0メモ▼
ゲージとティッカーを使う


ゲージとティッカーを使うプログラムです。



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

//ゲージとティッカーを使う(本体)
public class GaugeEx extends MIDlet {
    static MIDlet current;

    //コンストラクタ
    public GaugeEx(){
        current=this;
        (Display.getDisplay(this)).setCurrent(new GaugeForm());
    }

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

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

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


GaugeForm.java
import javax.microedition.lcdui.*;

//ゲージとティッカーを使う(フォーム)
class GaugeForm extends Form
    implements CommandListener {
    Gauge   gauge;//ゲージ
    Command soft1;//ソフトキー1

    //コンストラクタ
    GaugeForm(){
        super("GaugeEx");

        //ティッカーの設定
        setTicker(new Ticker("これはティッカーのテストです。"));

        //ゲージ
        gauge=new Gauge("gauge",true,10,5);
        append(gauge);

        //ソフトキー
        soft1=new Command("OK",Command.SCREEN,1);
        addCommand(soft1);
        setCommandListener(this);
    }

    //ソフトキーイベント
    public void commandAction(Command c,Displayable s) {
        //OK
        if (c==soft1) {
            //アラート
            Alert alert=new Alert("情報",
                "ゲージの値は"+gauge.getValue()+"です。",
                null,AlertType.INFO);
            alert.setTimeout(Alert.FOREVER);
            (Display.getDisplay(GaugeEx.current)).setCurrent(alert);
        }
    }
}



−戻る−