⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alertdemo.java

📁 J2ME MIDP 2.0 无线设备编程的一些源码
💻 JAVA
字号:
//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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -