alertdemo.java

来自「J2ME高级用户界面的学习代码」· Java 代码 · 共 79 行

JAVA
79
字号
//AlertDemo.javaimport javax.microedition.lcdui.*;import javax.microedition.midlet.MIDlet;public class AlertDemo extends MIDlet implements CommandListener{  private final static Command CMD_EXIT = new Command("EXIT",Command.EXIT,1);  private Alert alert;  private Form form;  private final int timeout = 10000;  public AlertDemo()  {    try    {      alert = new Alert("AlertDemo","Information Alert Running",Image.createImage("/information.png"),AlertType.INFO);      //alert.setTimeout(timeout);      alert.setTimeout(alert.FOREVER);      Gauge indicator = createIndicator(timeout);      alert.setIndicator(indicator);    }    catch(java.io.IOException e)    {      System.out.println(e.toString());    }    form = new Form("Next Screen");    form.append("Alert has done!");    form.addCommand(CMD_EXIT);    form.setCommandListener(this);  }  protected void startApp()  {    Display.getDisplay(this).setCurrent(alert,form);  }  protected void destroyApp(boolean unconditional){}  protected void pauseApp(){}  public void commandAction(Command c,Displayable d)  {    if(c == CMD_EXIT)    {      destroyApp(false);      notifyDestroyed();    }  }  private Gauge createIndicator(int maxValue)  {    if(maxValue == Alert.FOREVER)    {      return new Gauge(null,false,Gauge.INDEFINITE,Gauge.CONTINUOUS_RUNNING);    }    final int max = maxValue/1000;//指示器的最大值    final Gauge indicator = new Gauge(null,false,max,0);    new Thread()    {      public void run()      {        int value = 0;        while(value < max)        {          indicator.setValue(value);          ++value;          try          {            Thread.sleep(1000);          }          catch(InterruptedException ie){}        }      }    }.start();    return indicator;  }}

⌨️ 快捷键说明

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