📄 locationform.java
字号:
package com.wy.ch16;
import javax.microedition.lcdui.*;
import java.util.*;
public class LocationForm extends Form implements CommandListener {
private Command OKCommand;
private Command QuitCommand;
private TextField locationField;
private DateField d;
public LocationForm() {
super("输入地点");
locationField = new TextField("请输入地点", null, 10, TextField.ANY);
d = new DateField("旅行开始日期", DateField.DATE);
Date date=new Date();
d.setDate(date);
d.setLayout(Item.LAYOUT_CENTER);
OKCommand = new Command("确定", Command.OK, 1);
QuitCommand = new Command("退出", Command.EXIT, 1);
this.append(locationField);
this.append(d);
this.addCommand(OKCommand);
this.addCommand(QuitCommand);
this.setCommandListener(this);
}
public void commandAction(Command command, Displayable displayable) {
if (command == QuitCommand) {
MainMIDlet.getInstance().notifyDestroyed();
}
if (command == OKCommand) {
if (locationField.getString().equals("")) {
Alert a = new Alert("错误");
a.setType(AlertType.WARNING);
a.setString("请输入目的地点");
a.setTimeout(Alert.FOREVER);
Display.getDisplay(MainMIDlet.getInstance()).setCurrent(a);
} else {
Alert a = new Alert("请等待");
a.setType(AlertType.INFO);
a.setString("正在联网,请稍候");
a.setTimeout(Alert.FOREVER);
Display.getDisplay(MainMIDlet.getInstance()).setCurrent(a);
String location = locationField.getString();
String date=d.getDate().toString();
int index=0;
int beginindex=0;
int endindex=0;
String year="";
String month="";
String day="";
for(int i=0;i<date.length();i++){
if(date.charAt(i)==' '){
index++;
beginindex=endindex;
endindex=i;
if(index==2){
month=date.substring(beginindex+1,endindex);
}if(index==3){
day=date.substring(beginindex+1,endindex);
}
}
year=date.substring(endindex+1,date.length());
}
String months[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
for(int i=0;i<months.length;i++){
if(month.equals(months[i])){
month=new Integer(i+1).toString();
break;
}
}
if(day.startsWith("0")){
day=day.substring(1);
}
date=year+"-"+month+"-"+day;
new QueryThread(location,date, this).start();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -