alertwithindicatormidlet.java

来自「这是我在学习J2ME过程中」· Java 代码 · 共 54 行

JAVA
54
字号
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class AlertWithIndicatorMIDlet extends MIDlet
implements CommandListener
{
        private Display display;
        public AlertWithIndicatorMIDlet()
        {
                display = Display.getDisplay(this);
        }
        Gauge g ;
        public void startApp()
        {
                Alert al = new Alert("处理中");
                al.setType(AlertType.INFO);
                al.setTimeout(Alert.FOREVER);
                al.setString("系统正在处理中");

                g = new Gauge(null,false,10,0) ;
                al.setIndicator(g);

                Command start = new Command("开始",Command.OK,1) ;
                Command stop = new Command("停止",Command.STOP,1) ;
                al.addCommand(start);
                al.addCommand(stop);
                al.setCommandListener(this);
                display.setCurrent(al);
        }
        public void commandAction(Command c,Displayable s)
        {
                String cmd = c.getLabel() ;
                if(cmd.equals("开始"))
                {
                        for(int i=0 ; i <11 ; i++)
                        {
                                g.setValue(i);
                                try
                                {
                                        Thread.sleep(500);
                                }catch(Exception e){}
                        }
                }else if(cmd.equals("停止"))
                {
                        notifyDestroyed() ;
                }
        }
        public void pauseApp()
        {
        }
        public void destroyApp(boolean unconditional)
        {
        }
}

⌨️ 快捷键说明

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