alertdemo.java

来自「j2me無線學習源碼,一個無線連接的源碼,很有用的哦」· Java 代码 · 共 77 行

JAVA
77
字号
//alertDemo.java file
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class alertDemo extends MIDlet implements CommandListener
{
    private Command exitCommand, aCommand1, aCommand2, aCommand3, aCommand4;
    private Alert alert1, alert2, alert3, alert4;
    private TextBox tb;
    public alertDemo()
    {
        exitCommand =new Command("Exit",Command.EXIT,1);
        aCommand1 =new Command("OnlyTitle",Command.SCREEN,1);
        aCommand2 =new Command("Title&Info",Command.SCREEN,1);
        aCommand3 =new Command("withIcon",Command.SCREEN,1);
        aCommand4 =new Command("Forever",Command.SCREEN,1);
        tb =new TextBox("alertDemo","TextBox",40,0);

        alert1 = new Alert("only Title");
        alert2 = new Alert("Title","Alert Info Text!",null,AlertType.ALARM);
        try
        {
            alert3 = new Alert("Title","Alert Info Text!",Image.createImage("/warn.png"),AlertType.ALARM);
            alert4 = new Alert("Title","Alert Info Text!",Image.createImage("/announce.png"),AlertType.INFO);
        }
        catch (Exception e)
        {
            System.out.println("load image error");
        }
        alert3.setTimeout(1000*10); //将警告窗口设置为10秒后消失
        alert4.setTimeout(Alert.FOREVER);
        
        tb.addCommand(exitCommand);
        tb.addCommand(aCommand1);
        tb.addCommand(aCommand2);
        tb.addCommand(aCommand3);
        tb.addCommand(aCommand4);
        tb.setCommandListener(this);
    }
    protected void startApp(  ) throws MIDletStateChangeException
    {
        Display.getDisplay(this).setCurrent(tb);
    }

    protected void pauseApp(  )
    {
    }

    protected void destroyApp( boolean p1 )
    {
    }

    public void commandAction(Command c,Displayable d)
    {
        if (c ==exitCommand)
        {
            destroyApp(false);
            notifyDestroyed();
        }
        else if(c ==aCommand1)
        {
            Display.getDisplay(this).setCurrent(alert1,tb);
        }
        else if(c ==aCommand2)
        {
            Display.getDisplay(this).setCurrent(alert2,tb);
        }
        else if(c ==aCommand3)
        {
            Display.getDisplay(this).setCurrent(alert3,tb);
        }
        else if(c ==aCommand4)
        {
            Display.getDisplay(this).setCurrent(alert4,tb);
        }
    }
}

⌨️ 快捷键说明

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