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

📄 alertsmidlet.java

📁 j2me接口的例子,很不错的东东 可以做教程
💻 JAVA
字号:
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class AlertsMIDlet extends MIDlet implements CommandListener {
    
    //定义不同类型的Alert对象
	private Alert info;
    private Alert warning;
    private Alert alarm;
    private Alert confirm;
    private Alert error;

    //定义不同类型的Command对象
    private Command alarmComm;
    private Command confirmComm;
    private Command errorComm;
    private Command infoComm;
    private Command warningComm;
    private Command exitComm;

    private Display display;

    public AlertsMIDlet() {

        exitComm = new Command("离开", Command.EXIT, 1);
        alarmComm = new Command("警报", Command.SCREEN,1);
        confirmComm = new Command("确认", Command.SCREEN, 1);
        errorComm = new Command("错误", Command.SCREEN, 1);
        infoComm = new Command("资讯", Command.SCREEN, 1);
        warningComm = new Command("警告", Command.SCREEN, 1);
        display = Display.getDisplay(this);
    }

    public void startApp() {
        TextBox t = new TextBox("Hello", "请按键选择Alert种类!", 200, 0);
        
        confirm = new Alert("确认", "确认信息", null,
                                 AlertType.CONFIRMATION);
		confirm.setTimeout(4000);

        error = new Alert("错误", "错误信息", null, AlertType.ERROR);
		error.setTimeout(4000);
		
		alarm = new Alert("警报", "警报信息", null, AlertType.ALARM);
		alarm.setTimeout(4000);

        info = new Alert("资讯", "资讯信息", null, AlertType.INFO);
		info.setTimeout(4000);

        warning = new Alert("警告", "警告信息", null,AlertType.WARNING);
        
        warning.setTimeout(Alert.FOREVER);

        t.addCommand(exitComm);
        t.addCommand(errorComm);
		t.addCommand(confirmComm);
		t.addCommand(alarmComm);
        t.addCommand(infoComm);        
		t.addCommand(warningComm);

        t.setCommandListener(this);
        display.setCurrent(t);
    }

    public void pauseApp() {}

    public void destroyApp(boolean unconditional) {}

    public void commandAction(Command c, Displayable dis) {
    	
    	String comm = c.getLabel();
    	
        if (comm.equals("离开")) {
            destroyApp(false);
            notifyDestroyed();
        }
        if (comm.equals("警报")) {
            display.setCurrent(alarm);
        }
        if (comm.equals("确认")) {
            display.setCurrent(confirm);
        }
        if (comm.equals("错误")) {
            display.setCurrent(error);
        }
        if (comm.equals("资讯")) {
            display.setCurrent(info);
        }
        if (comm.equals("警告")) {
            display.setCurrent(warning);
        }
    }
}

⌨️ 快捷键说明

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