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

📄 alertdemo2.java

📁 J2ME MIDP 2.0 无线设备编程的一些源码
💻 JAVA
字号:
//alertDemo2.java file
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class alertDemo2 extends MIDlet implements CommandListener
{
    private Command exitCommand, aCommand1, aCommand2, commandNo, commandYes;
    private Alert alert1, alert2;
    private TextBox tb;
    public alertDemo2()
    {
        exitCommand =new Command("Exit",Command.EXIT,0);
        aCommand1 =new Command("Alert",Command.SCREEN,1);
        aCommand2 =new Command("DISMISS",Command.SCREEN,1);
        commandNo =new Command("NO",Command.CANCEL,1);
        commandYes =new Command("YES",Command.OK,2);
        tb =new TextBox("alertDemo2","TextBox",40,0);

        try
        {
            alert1 = new Alert("Title","YES or NO Demo Alert Window !!!",Image.createImage("/warn.png"),AlertType.INFO);
            alert2 = new Alert("Title","DISMISS_COMMAND Demo Alert Window !!!",Image.createImage("/announce.png"),AlertType.INFO);
        }
        catch (Exception e)
        {
            System.out.println("load image error");
        }
        alert2.setTimeout(Alert.FOREVER);
        
        tb.addCommand(exitCommand);
        tb.addCommand(aCommand1);
        tb.addCommand(aCommand2);
        tb.setCommandListener(this);

        alert1.addCommand(commandYes);
        alert1.addCommand(commandNo);
        alert1.setCommandListener(this);

        alert2.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 ==commandYes)
        {
            System.out.println("YES selected");
            tb.setString("YES selected");
            Display.getDisplay(this).setCurrent(tb);
        }
        else if(c ==commandNo)
        {
            System.out.println("NO selected");
            tb.setString("NO selected");
            Display.getDisplay(this).setCurrent(tb);
        }
        else if(c ==commandNo)
        {
            System.out.println("NO selected");
            tb.setString("NO selected");
            //必须手工设置当前需要显示的对象
            Display.getDisplay(this).setCurrent(tb);
        }
        else if(c ==Alert.DISMISS_COMMAND)
        {
            System.out.println("DISMISS_COMMAND selected");
            tb.setString("DISMISS_COMMAND selected");
            //必须手工设置当前需要显示的对象
            Display.getDisplay(this).setCurrent(tb);
        }
    }
}

⌨️ 快捷键说明

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