📄 mycalendar.java
字号:
// 程序名MyCalendar.java
// 测试Timer和TimerTask
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
public class MyCalendar extends MIDlet implements CommandListener {
private Display display;
private Form calendarForm;
private Form mainForm;
private Command cmdExit;
private Command cmdAdd;
private Command cmdCancel;
private Command cmdOK;
private DateField dateField;
private TextField msgField;
Timer timer = new Timer();
public MyCalendar() {
display = Display.getDisplay(this);
cmdExit = new Command("Exit", Command.SCREEN, 1);
cmdAdd = new Command("Add", Command.SCREEN, 1);
mainForm = new Form("Add a task");
mainForm.addCommand(cmdExit);
mainForm.addCommand(cmdAdd);
mainForm.setCommandListener(this);
cmdCancel = new Command("Cancel", Command.SCREEN, 1);
cmdOK = new Command("OK", Command.SCREEN, 1);
dateField = new DateField("My Calendar",DateField.DATE_TIME);
dateField.setDate(new Date(System.currentTimeMillis()));
msgField = new TextField("Message:","",100,0);
calendarForm = new Form("Test DateField");
calendarForm.append(dateField);
calendarForm.append(msgField);
calendarForm.addCommand(cmdCancel);
calendarForm.addCommand(cmdOK);
calendarForm.setCommandListener(this);
}
public void startApp() {
display.setCurrent(mainForm);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if (c == cmdExit) {
destroyApp(false);
notifyDestroyed();
} else if (c == cmdAdd) {
display.setCurrent(calendarForm);
} else if (c == cmdCancel) {
display.setCurrent(mainForm);
} else if (c == cmdOK) {
display.setCurrent(mainForm);
timer.schedule(new AlertTask(msgField.getString(),mainForm),dateField.getDate());
}
}
class AlertTask extends TimerTask {
String message = "";
Displayable d;
AlertTask(String message,Displayable d) {
this.message = message;
this.d = d;
}
public void run(){
Alert alert = new Alert("Alert!", message, null, null );
alert.setTimeout( Alert.FOREVER );
display.setCurrent(alert,d);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -