代码分析J2ME2Word文档下载推荐.docx
《代码分析J2ME2Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《代码分析J2ME2Word文档下载推荐.docx(18页珍藏版)》请在冰豆网上搜索。
privateStringCity,Start,End;
//inputForm用于放置TFCity,TFStart,TFEnd等组件;
returnForm用于放置查询结果
privateForminputForm,returnForm;
//声明一个Alert
privateAlertanAlert;
//声明Ticker
privateTickeraTicker;
//声明一个图片
privateImageanImage;
publicMGJCCX(){
//定义用于输入信息的TextField
TFCity=newTextField("
City:
"
"
30,TextField.ANY);
//城市
TFStart=newTextField("
Start:
//当前点
TFEnd=newTextField("
End:
//目标点
try{
anImage=Image.createImage("
/welcome.png"
);
}
catch(IOExceptionioe){
ioe.printStackTrace();
}
aTicker=newTicker("
欢迎使用移动公交车查询系统"
anAlert=newAlert("
版权声明!
Copyright@2005ShenzhenPolytechnic,AllRightsReserved."
anImage,AlertType.CONFIRMATION);
inputForm=newForm("
输入查找信息:
returnForm=newForm("
查询结果:
//在Form中添加三个TextField及按钮,即界面布置
inputForm.append(TFCity);
inputForm.append(TFStart);
inputForm.append(TFEnd);
publicvoidstartApp()throwsMIDletStateChangeException{
anAlert.setTimeout(Alert.FOREVER);
display=Display.getDisplay(this);
display.setCurrent(anAlert,inputForm);
inputForm.setTicker(aTicker);
publicvoidpauseApp(){
publicvoiddestroyApp(booleanunconditional){
}
【项目4-8】Command事件处理
理解创建高级事件处理的步骤
实现按钮事件
实现按钮事件*/
publicclassMGJCCXextendsMIDletimplementsCommandListener{
privateCommandcmdSend,cmdBack,cmdExit;
TFCity=newTextField("
TFStart=newTextField("
TFEnd=newTextField("
try{
//定义用于处理的发送与返回按钮
cmdSend=newCommand("
Send"
Command.SCREEN,1);
cmdBack=newCommand("
Back"
cmdExit=newCommand("
Exit"
Command.EXIT,1);
inputForm=newForm("
returnForm=newForm("
//在Form中添加三个TextField及按钮,即界面布置
inputForm.append(TFCity);
inputForm.append(TFStart);
inputForm.append(TFEnd);
inputForm.addCommand(cmdSend);
inputForm.addCommand(cmdExit);
inputForm.addCommand(cmdBack);
inputForm.setCommandListener(this);
publicvoidstartApp()throwsMIDletStateChangeException{
anAlert.setTimeout(Alert.FOREVER);
inputForm.setTicker(aTicker);
publicvoidcommandAction(Commandcmd,Displayabledis){
if(cmd==cmdBack){
display.setCurrent(inputForm);
elseif(cmd==cmdExit){
destroyApp(true);
notifyDestroyed();
//当点击按钮Send时,获取输入在TexfField中的城市、当前点和目标点的信息
elseif(cmd==cmdSend){
City=TFCity.getString();
Start=TFStart.getString();
End=TFEnd.getString();
}
【项目4-9】TextBox测试程序
掌握TextBox的构造方法
实现在TextBox屏幕上输入一串字符
NewTextBox.java*/
实现在TextBox屏幕上输入一串字符*/
publicclassNewTextBoxextendsMIDletimplementsCommandListener{
privateCommandcmdExit;
privateTextBoxaTextBox;
publicNewTextBox(){
cmdExit=newCommand("
aTextBox=newTextBox("
TextBox示例"
在TextBox中显示123456"
17,TextField.ANY);
aTextBox.addCommand(cmdExit);
aTextBox.setCommandListener(this);
display=Display.getDisplay(this);
display.setCurrent(aTextBox);
if(cmd==cmdExit){
destroyApp(true);
【项目4-10】List测试程序
掌握List的构造方法
获取List上的属性
NewList.java*/
获取List上的属性*/
publicclassNewListextendsMIDletimplementsCommandListener{
privateCommandcmdExit,cmdOK,cmdBack;
privateListmyScreen;
publicNewList(){
initList();
voidinitList(){
StringstringElements[]={"
Read"
"
Write"
Delete"
};
ImageimageElements[]={Image.createImage("
/single1.png"
),
Image.createImage("
/single2.png"
/single3.png"
)};
myScreen=newList("
EMAIL"
Choice.EXCLUSIVE,stringElements,imageElements);
}
catch(Exceptione){
}
cmdOK=newCommand("
OK"
Command.SCREEN,1);
cmdExit=newCommand("
Command.EXIT,1);
cmdBack=newCommand("
myScreen.addCommand(cmdExit);
myScreen.addCommand(cmdOK);
myScreen.setCommandListener(this);
display.setCurrent(myScreen);
elseif(cmd==cmdOK){
aTextBox=newTextBox("
TextBox"
Theindexis:
+myScreen.getSelectedIndex()+"
andthe”+
“Labelis:
+myScreen.getString(myScreen.getSelectedIndex()),
40,TextField.ANY);
aTextBox.addCommand(cmdBack);
aTextBox.setCommandListener(this);
display.setCurrent(aTextBox);
elseif(cmd==cmdBack){
【项目4-11】ChoiceGroup测试程序
掌握ChoiceGroup的创建方法
在Form对象上放置ChoiceGroup对象
在Form对象上放置ChoiceGroup对象*/
publicclassNewChoiceGroupextendsMIDletimplementsCommandListener{
privateChoiceGroupaChoiceGroup;
privateFormaForm;
publicNewChoiceGroup(){
initChoiceGroup();
voidinitChoiceGroup(){
try{
aChoiceGroup=newChoiceGroup("
EMAIL:
Choice.EXCLUSIVE);
aChoiceGroup.append("
null);
aForm=newForm("
ChoiceGroup"
aForm.append(aChoiceGroup);
aForm.addCommand(cmdExit);
aForm.setCommandListener(this);
display.setCurrent(aForm);
【项目4-12】ItemStateListener事件处理
理解创建ItemStateListener事件处理的步骤
实现ItemStateListener事件
NewItemListener.java*/
实现ItemStateListener事件*/
publicclassNewItemListenerextendsMIDletimplements
CommandListener,ItemStateListener{
publicNewItemListener(){
Choice.EXCLUSIVE);
aForm.setItemStateListener(this);
publicvoidstartAp