📄 datefieldtest.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
public class DateFieldTest extends MIDlet implements Runnable, CommandListener{
Display display;
Form form;
DateField schedule;
Command exitCmd;
Command resetCmd;
Command changeCmd;
Command okCmd;
Command cancelCmd;
Command stopCmd;
Ticker alarm;
TextBox editor;
Thread thread;
boolean stop = false;
public DateFieldTest(){
display = Display.getDisplay(this);
form = new Form("会议登陆");
schedule = new DateField("新增会议",DateField.DATE_TIME);
alarm = new Ticker("尚无即将召开的会议");
editor = new TextBox("输入会议名称","",10,TextField.ANY);
thread = new Thread(this);
exitCmd = new Command("退出", Command.EXIT, 1);
changeCmd = new Command("修改会议名称", Command.SCREEN, 1);
resetCmd = new Command("重设", Command.SCREEN, 2);
okCmd = new Command("确定", Command.OK, 1);
stopCmd = new Command("关闭声音", Command.STOP, 1);
cancelCmd = new Command("取消", Command.CANCEL, 1);
form.setTicker(alarm);
form.append(schedule);
form.addCommand(exitCmd);
form.addCommand(resetCmd);
form.addCommand(changeCmd);
form.setCommandListener(this);
editor.addCommand(okCmd);
editor.addCommand(cancelCmd);
editor.setCommandListener(this);
}
public void startApp(){
display.setCurrent(form);
thread.start();
}
public void run(){
while(true){
Date current = new Date();
Date set = schedule.getDate();
if((set!=null) && ((set.getTime()-current.getTime()) < 1000)){
form.addCommand(stopCmd);
alarm.setString("会议时间到!");
while(!stop){
try{
Thread.sleep(5000);
AlertType.ALARM.playSound(display);
}catch(Exception ex){}
}
form.removeCommand(stopCmd);
break;
}
}
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
public void commandAction(Command c, Displayable d){
if(c == exitCmd){
destroyApp(true);
notifyDestroyed();
}
else if(c == changeCmd){
display.setCurrent(editor);
}
else if(c == resetCmd){
schedule.setDate(new Date());
}
else if(c == stopCmd){
stop = true;
}
else if(c == okCmd){
schedule.setLabel(editor.getString());
display.setCurrent(form);
}
else if(c == cancelCmd){
display.setCurrent(form);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -