Mobile编程题.doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《Mobile编程题.doc》由会员分享,可在线阅读,更多相关《Mobile编程题.doc(6页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、服务器端代码:public class ServerMIDlet extends MIDlet protected void startApp() throws MIDletStateChangeException /监听9999端口try ServerSocketConnection ssc=( ServerSocketConnection)Connector.open(socket:/:9999);/建立连接 /获得服务器端的IP地址和接口 System.out.println(ssc.getLocalAddress(); System.out.println(ssc.getLocalPo
2、rt(); SocketConnection sc=(SocketConnection)ssc.acceptAndOpen(); /等待客户端连接,如果没有客户端连接,程序就在这里阻塞。 /若果有客户端连接,就会返回一个SocketConnection对象,充当通讯的桥梁。 /以后就可以使用sc与客户端进行通讯了 /获取客户端信息 System.out.println(这是服务器的信息=客户端+sc.getAddress(); /获取客户端发送过来的字符串 DataInputStream dis=sc.openDataInputStream(); String msg=dis.readUTF(
3、);/如果没有读到内容,就阻塞 System.out.println(这是服务器接收到的内容:+msg); /服务器给客户端发送欢迎辞 DataOutputStream dos=sc.openDataOutputStream(); dos.writeUTF(欢迎连接服务器); catch (IOException e) 1. 使用J2ME开发一个网络程序,客户端连上服务器,能够送给服务端一个“你好”,服务器端也能够发送给客户端“欢迎连接服务器”。分别写出服务器端和客户端的程序。客户端代码:public class ClientMIDlet extends MIDlet protected vo
4、id startApp() throws MIDletStateChangeException try SocketConnection sc=(SocketConnection)Connector.open(socket:/192.168.0.40:9999);DataOutputStream dos=sc.openDataOutputStream();dos.writeUTF(你好,服务器,我是客户端);/接收服务器端的欢迎辞DataInputStream dis=sc.openDataInputStream();String msg=dis.readUTF();System.out.pr
5、intln(这是客户端接受到的欢迎辞:+msg); catch (IOException e) 2. 模拟手机写短信程序。编程要求:a) 程序载入,出现一个欢迎界面,右下按钮:写短信;左下按钮是:退出程序。b) 选择“写短信”按钮,进入短信编辑界面,界面上有一个文本框输入短信。框内有字时左下方显示:清除文本,否则显示:返回上一个界面:右下方显示按钮:发送。c) 按“发送“,出现一个界面,左下方显示:返回;右下方显示:确定。上面有一个文本框输入对方电话号码,电话号码输入之后,按右下方的“确定”按钮,短信发出,在控制台上显示。以上要求必须至少写出两个界面和至少两个时间处理。public class
6、 MessageMidlet extends MIDlet implements CommandListener,ItemStateListenerprivate Display dis;/*欢迎界面*/private Form welcomeForm = new Form(欢迎界面);private ImageItem welcomeItem;private Command cmdExit = new Command(退出程序, Command.EXIT , 1);private Command cmdWriteMsg = new Command(写短信 , Command.SCREEN ,
7、 1);/*短信编辑(写短信)界面*/private Form frmMsg = new Form(请您输入短信);private TextField tfMsg = new TextField(null, null, 255, TextField.ANY );private Command cmdMsgBack = new Command(返回,Command.BACK ,1);private Command cmdMsgDel = new Command(清除文本,Command.BACK ,1);private Command cmdSend = new Command(发送,Comma
8、nd.SCREEN ,1);/*短信发送界面*/private TextBox tbPhone = new TextBox(请输入对方的手机号码, null, 15, TextField.NUMERIC);private Command cmdPhoneBack = new Command(返回, Command.BACK , 1);private Command cmdOk = new Command(确定,Command.SCREEN ,1);public MessageMidlet() Image welcomeImg = null;try welcomeImg = Image.crea
9、teImage(/bg.jpg);catch(Exception e)e.printStackTrace(); welcomeItem = new ImageItem(欢迎您的到来, welcomeImg,Item.LAYOUT_CENTER, null);protected void startApp() throws MIDletStateChangeException dis =Display.getDisplay(this);dis.setCurrent(welcomeForm);/*欢迎界面初始化*/welcomeForm.append(welcomeItem);welcomeFor
10、m.addCommand(cmdExit);welcomeForm.addCommand(cmdWriteMsg);/*短信编辑界面初始化*/frmMsg.append(tfMsg);frmMsg.addCommand(cmdMsgBack);/frmMsg.addCommand(cmdSend);frmMsg.addCommand(cmdSend);/*发送短信界面初始化*/tbPhone.addCommand(cmdPhoneBack);tbPhone.addCommand(cmdOk);/*事件监听绑定代码*/welcomeForm.setCommandListener(this);fr
11、mMsg.setCommandListener(this);frmMsg.setItemStateListener(this);tbPhone.setCommandListener(this);public void commandAction(Command c, Displayable d) if(c=cmdExit) this.notifyDestroyed(); else if(c=cmdWriteMsg) dis.setCurrent(frmMsg); else if (c=cmdMsgBack) dis.setCurrent(welcomeForm); else if(c=cmdM
12、sgDel) int position=tfMsg.getCaretPosition(); tfMsg.delete(position -1,1); if(tfMsg.size()=0) frmMsg.removeCommand(cmdMsgDel);frmMsg.addCommand(cmdMsgBack); else if(c=cmdSend)dis.setCurrent(tbPhone);else if (c=cmdPhoneBack)dis.setCurrent(frmMsg);else if(c=cmdOk) System.out.println(短信成功发出);System.out
13、.println(短信内容 + tfMsg.getString();System.out.println(短信发送目的地 + tbPhone.getString();dis.setCurrent(welcomeForm);public void itemStateChanged(Item item) if(item=tfMsg)f(tfMsg.size()!=0) frmMsg.removeCommand(cmdMsgBack);frmMsg.addCommand(cmdMsgDel);3. 动画模拟:界面上有个小红球,要求能够慢慢掉下来然后弹起来,要包含暂停和继续的功能。public cla
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Mobile 编程
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内