日期:2014-05-20 浏览次数:20931 次
DateField是一个时间控件,使用起来也是非常简单的,里面已经帮我们实现了很多的功能,如设置时间和保存等等。界面也是很可爱的。是一个时钟的样子。下面就是一个程序和截图:
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;
public class DateFieldDemo extends MIDlet implements CommandListener {
private Command exitCommand = new Command("Exit",Command.EXIT,1);
private boolean firstTime;
private Form mainForm;
public DateFieldDemo() {
??
?? mainForm = new Form("The Time");
?? mainForm.append(new DateField("查看时间",DateField.TIME));//添加了DateField时间控件
?? mainForm.addCommand(exitCommand);
?? mainForm.setCommandListener(this);??
??
}
public void commandAction(Command c, Displayable d) {
??
?? if(c == exitCommand)
?? {
??? try {
???? destroyApp(false);
??? } catch (MIDletStateChangeException e) {
???? // TODO Auto-generated catch block
???? e.printStackTrace();
??? }
??? notifyDestroyed();
?? }
??
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
??
}
protected void pauseApp() {
??
}
protected void startApp() throws MIDletStateChangeException {
??
?? Display.getDisplay(this).setCurrent(mainForm);
}
?
}
?