dialog.java
来自「这是我收集的别人写的关于基本控件的例子」· Java 代码 · 共 98 行
JAVA
98 行
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
class DialogListener {
public void onOK() { };
public void onYES() { };
public void onNO() { };
public void onCANCELK() { };
public void onCONFOIRM() { };
}
public class Dialog extends Form implements CommandListener {
Display display;
DialogListener dll;
Displayable parent;
public static final int OK = 1;
public static final int YES = 2;
public static final int NO = 4;
public static final int CANCEL = 8;
public static final int CONFIRM = 16;
Command cmOK;
Command cmYES;
Command cmNO;
Command cmCANCEL;
Command cmCONFIRM;
StringItem text;
public Dialog(String title, String text, int mode, MIDlet midlet,
DialogListener dll, Displayable dis) {
super(title);
this.dll = dll;
this.text = new StringItem(null, text);
this.display = Display.getDisplay(midlet);
this.parent = dis;
if ((mode & OK) != 0) {
cmOK = new Command("确定", Command.OK, 1);
addCommand(cmOK);
}
if ((mode & YES) != 0) {
cmYES = new Command("是", Command.OK, 1);
addCommand(cmYES);
}
if ((mode & CANCEL) != 0) {
cmCANCEL = new Command("取消", Command.CANCEL, 1);
addCommand(cmCANCEL);
}
if ((mode & CONFIRM) != 0) {
cmCONFIRM = new Command("应用", Command.SCREEN, 1);
addCommand(cmCONFIRM);
}
if ((mode & NO) != 0) {
cmNO = new Command("否", Command.EXIT, 1);
addCommand(cmNO);
}
append(text);
setCommandListener(this);
}
public void commandAction(Command c, Displayable s) {
if (dll != null) {
if (c == cmOK)
dll.onOK();
else if (c == cmYES)
dll.onYES();
else if (c == cmNO)
dll.onNO();
else if (c == cmCANCEL)
dll.onCANCELK();
else if (c == cmCONFIRM)
dll.onCONFOIRM();
}
display.setCurrent(parent);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?