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

📄 fewalertsmidlet.java

📁 j2me的程序
💻 JAVA
字号:
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

// A first MIDlet with simple text and a few commands.
public class FewAlertsMIDlet extends MIDlet
		         implements CommandListener {

  //The exit, info, and buy commands
  private Command exitCommand;
  private Command alarmCommand;
  private Command confirmCommand;
  private Command errorCommand;
  private Command infoCommand;
  private Command warningCommand;

  private Alert alarmAlert;
  private Alert confirmAlert;
  private Alert errorAlert;
  private Alert infoAlert;
  private Alert warningAlert;

  //The display for this MIDlet
  private Display display;

  public FewAlertsMIDlet() {
    display = Display.getDisplay(this);
    exitCommand = new Command("离开", Command.SCREEN, 1);
    alarmCommand = new Command("警报",Command.SCREEN, 2);
    confirmCommand = new Command("确认",Command.SCREEN, 2);
    errorCommand = new Command("错误",Command.SCREEN, 2);
    infoCommand = new Command("资讯",Command.SCREEN, 2);
    warningCommand = new Command("警告",Command.SCREEN, 2);


  }

  // Start the MIDlet by creating the TextBox and
  // associating the exit command and listener.
  public void startApp() {
    TextBox main=new TextBox("主画面","请按软键选择要执行的Alert",256,TextField.ANY);
    alarmAlert = new Alert("警报","这是一个\"警报\"信息窗口",null,AlertType.ALARM);
    confirmAlert = new Alert("确认","这是一个\"确认\"信息窗口",null,AlertType.CONFIRMATION);
    errorAlert = new Alert("错误","这是一个\"错误\"信息窗口",null,AlertType.ERROR);

    Image infoImage = null;
    try{
       infoImage = Image.createImage("/Sokoban.png");
    }
    catch(IOException e){
    }

    infoAlert = new Alert("资讯","这是一个\"资讯\"信息窗口",infoImage,AlertType.INFO);
    warningAlert = new Alert("警告","这是一个\"警告\"信息窗口",null,AlertType.WARNING);

    alarmAlert.setTimeout(Alert.FOREVER);
    confirmAlert.setTimeout(3000);
    errorAlert.setTimeout(3000);
    infoAlert.setTimeout(3000);
    warningAlert.setTimeout(3000);


    main.addCommand(exitCommand);
    main.addCommand(alarmCommand);
    main.addCommand(confirmCommand);
    main.addCommand(errorCommand);
    main.addCommand(infoCommand);
    main.addCommand(warningCommand);


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

  // Pause is a no-op because there are no background
  // activities or record stores to be closed.
  public void pauseApp() { }

  // Destroy must cleanup everything not handled
  // by the garbage collector.
  // In this case there is nothing to cleanup.
  public void destroyApp(boolean unconditional) { }

  // Respond to commands. Here we are only implementing
  // the exit command. In the exit command, cleanup and
  // notify that the MIDlet has been destroyed.
  public void commandAction(Command c, Displayable s) {
    if (c == exitCommand) {
      destroyApp(false);
      notifyDestroyed();
    }
    if (c == alarmCommand) {
	      display.setCurrent(alarmAlert);
    }
    if (c == confirmCommand) {
	      display.setCurrent(confirmAlert);
    }
    if (c == errorCommand) {
	     display.setCurrent(errorAlert);
    }
    if (c == infoCommand) {
	     display.setCurrent(infoAlert);
    }
    if (c == warningCommand) {
	      display.setCurrent(warningAlert);
    }
  }
}

⌨️ 快捷键说明

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