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

📄 alerttest.java

📁 《精彩的手机UI例程.zip》是很好的手机编辑软件
💻 JAVA
字号:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class AlertTest extends MIDlet implements CommandListener{
    private TextBox textBox;
    private Command okCommand = new Command("OK", Command.OK, 1);
    private Command exitCommand = new Command("EXIT", Command.EXIT, 1);
    private Display display;	
      
    public AlertTest() {
        //create an exclusive list
	textBox= new TextBox("Type in a 6-character word","",20,TextField.ANY);
	textBox.addCommand(okCommand);
	textBox.addCommand(exitCommand);
	textBox.setCommandListener(this);
		
	//retrieve display object 
	display=Display.getDisplay(this);
    }
    
    public void startApp() throws MIDletStateChangeException {
        display.setCurrent(textBox);
    }

    /**
     * Pause the MIDlet
     */
    public void pauseApp() {
    }

    /**
     * Called by the framework before the application is unloaded
     */
    public void destroyApp(boolean unconditional) {
	textBox=null;
	okCommand = null;
	exitCommand = null;
        display=null;
    }

    public void commandAction(Command c, Displayable d) {
        if(d==textBox && c==okCommand) {
            String t=textBox.getString();
            if(t.length()==6) {
                Alert info= new Alert("Success",
                                       "Good word. Try again.",
                                       null,
                                       AlertType.INFO);
                info.setTimeout(Alert.FOREVER);
                display.setCurrent(info,textBox);
            }
            else {
                Image err_img= null;
                //create error image
                try {
                    err_img=Image.createImage("/error.png");
                }catch(Exception e){
                    System.out.println("image is not created.");
                }
                Alert error= new Alert("Error",
                                       "Sorry not right. Try again.",
                                       err_img,
                                       AlertType.ERROR);
                error.setTimeout(Alert.FOREVER);
                display.setCurrent(error,textBox);
            }
	}
        else if(c==exitCommand) {
            destroyApp(true);
            notifyDestroyed();
        }
    }
}

⌨️ 快捷键说明

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