请高手帮帮忙,急急!!!

qiujihao 2007-05-29 10:51:37
我老师要求做一段手机订票程序。本人在网上搞了一段,但是还缺数据与服务器交互、连接的片段。请高手帮忙补完,谢谢了。
程序如下:


package demo;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.io.*;

import com.sun.cldc.i18n.StreamReader;
public class asktickets extends MIDlet implements
CommandListener{
private Display display;
private TextField date,startstation,stopstation;
private List type;
private TextBox textinf;
private Form questionform,resultform;
private Command cmdnext;
private Command cmdexit;
private Command cmdconf;
private Command cmdcanc;
private Command cmdsend;
private Alert alert1;
public asktickets () {
super ();
display =Display.getDisplay(this);
startstation = new TextField ("起点站输入","", 20, 0) ;
stopstation = new TextField ("终点站输入","", 20, 0) ;
date = new TextField ("乘车日期输入(格式如20020312) :","" ,20, 0) ;
String[] typestr = {"硬座","软卧","硬卧上铺","硬卧中铺","硬卧下铺"};
type = new List("请选择乘坐席别: ", List. EXCLUSIVE,typestr, null) ;
textinf = new TextBox("您要查询的信息为", null, 60, 0) ;
questionform = new Form ("查询输入: ") ; //查询窗
questionform.append ( startstation) ; //起点站输入框
questionform.append ( stopstation) ;//终点站输入框
questionform.append ( date) ; //乘车日期输入框
questionform.addCommand ( cmdnext) ;
questionform.addCommand ( cmdexit) ;
questionform.setCommandListener( this) ;
type.addCommand ( cmdconf) ; //乘坐席别无选择
type.addCommand ( cmdcanc) ;
type.setCommandListener( this) ;
textinf. addCommand ( cmdsend) ; //查询输入的总信息回显框
textinf. addCommand ( cmdcanc) ;
textinf. setCommandListener( this) ;
resultform = new Form ("查询结果") ; //查询结果框
resultform. addCommand ( cmdexit) ;
resultform. setCommandListener( this) ;
}
public void startApp ( )
{
display.setCurrent(questionform) ; }
public void pauseApp ( ) { }
public void destroyApp ( boolean unconditional) { }
public void commandAction (Command c,Displayable d )
{
String strstartstation = new String(startstation.getString( ) ) ;
//获取起点站输入内容
String strstopstation = new String(stopstation.getString( ) ) ;
//获取终点站输入内容
String strdate = new String( date.getString( ) ) ; //获取乘车日期内容
String strtype; //获取乘坐席别
int itype = type.getSelectedIndex( );
switch ( itype) {
case 0: strtype ="硬坐"; break;
case 1: strtype ="软卧"; break;
case 2: strtype ="硬卧上铺"; break;
case 3: strtype ="硬卧中铺" ;break;
default: strtype ="硬卧下铺";
}
String inf ="起点站: \n"+ strstartstation +"\n 终点站: \n"
+ strstopstation +"\n乘车日期: \n"+ strdate +"\n乘车席别: \n"+
strtype;
if ( c == cmdnext) {
if ( strstartstation == null| strstopstation == null | strdate == null)
{ alert1 = new Alert ("警告: ","输入不能为空! \n 请重新输入!",
null,AlertType.INFO) ;
alert1. setTimeout(5000) ;
display.setCurrent( questionform) ;
}
else{
display.setCurrent( type) ;
}
}
if ( c == cmdconf) {
textinf. setString( inf) ;
display.setCurrent( textinf) ;
}
if ( c == cmdcanc) { display.setCurrent( questionform) ; }
if ( c == cmdsend) {
String resultinf = isred;
resultform.append ( resultinf) ;
display.setCurrent( resultform) ;
}
if ( c == cmdexit) {
destroyApp ( false) ;
notifyDestroyed ( ) ;
}
}
//与服务器连接片段(主要补这段)
HttpConnection con = (HttpConnection)Connector.open ( targetURL);
is = con.openInputStream ( ) ;
InputStreamReader isred = new;
InputStreamReader( is,"GBK") ;
Isred.read( buf, 0, 100) ;
...全文
210 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dongdong715 2007-05-30
  • 打赏
  • 举报
回复
晕,,没见过LZ这样问别人问题的,竟然叫人补程序,,也真够懒的,
liq330 2007-05-30
  • 打赏
  • 举报
回复
哈哈,是啊,就算我是高手,要帮你补代码基本上是没空了,不是不够热心,而是没那个时间,理解一下高手吧,哈哈,我是新手.
wormwormwormworm 2007-05-30
  • 打赏
  • 举报
回复
高手哪有空理你这个,呵呵,凡事靠自己

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧