📄 datemidlet.java
字号:
package com.j2medev.sample.chapter3;
import java.util.Calendar;
import java.util.Date;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class DateMidlet extends MIDlet implements CommandListener{
private Form form = new Form("UIDemo");
private Display display = null;
private DateField time = null;
private Command okCommand = new Command("确定",Command.OK,1);
public void startApp() {
if(display==null) {
display = Display.getDisplay(this);
time = new DateField("输入时间和日期", DateField.DATE_TIME);
time.setDate(new java.util.Date());
form.append(time);
form.addCommand(okCommand);
form.setCommandListener(this);
display.setCurrent(form);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command cmd,Displayable displayable){
if(cmd == okCommand){
Date d = time.getDate();
Calendar calendar = Calendar.getInstance();
calendar.setTime(d);
System.out.println(calendar.get(Calendar.YEAR));
//其他get()方法可以读取例如MONTH等属性值
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -