📄 alertdemo.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.IOException;
public class AlertDemo extends MIDlet implements CommandListener {
private Display display;
private Command cmdOK = new Command("确定", Command.OK, 1);
private Command cmdExit = new Command("退出", Command.EXIT, 1);
public void startApp() {
TextBox password = new TextBox("请输入密码", "", 10,
TextField.PASSWORD|TextField.ANY);
password.addCommand(cmdOK);
password.addCommand(cmdExit);
password.setCommandListener(this);
display = Display.getDisplay(this);
display.setCurrent(password);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command cmd, Displayable d) {
if(cmd == cmdOK) {
String psw = ((TextBox)d).getString();
if(psw.equals("Yang Guang")) {
Image img = null;
try {
img = Image.createImage("/ok.png");
}
catch(IOException ioe) {
//
}
Alert alert = new Alert("提示", "您输入的密码正确",
img, AlertType.INFO);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert, display.getCurrent());
}
else {
Alert alert = new Alert("错误!",
"您输入的密码: \" " + psw + "\"错误",
null, AlertType.ERROR);
alert.setTimeout(2000); //延迟2秒
display.setCurrent(alert, display.getCurrent());
}
}
else if(cmd == cmdExit) {
notifyDestroyed();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -