J2me手机游戏存储玩家分数源码

上传人:宝路 文档编号:22272206 上传时间:2017-11-26 格式:DOC 页数:6 大小:41.03KB
返回 下载 相关 举报
J2me手机游戏存储玩家分数源码_第1页
第1页 / 共6页
J2me手机游戏存储玩家分数源码_第2页
第2页 / 共6页
J2me手机游戏存储玩家分数源码_第3页
第3页 / 共6页
J2me手机游戏存储玩家分数源码_第4页
第4页 / 共6页
J2me手机游戏存储玩家分数源码_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《J2me手机游戏存储玩家分数源码》由会员分享,可在线阅读,更多相关《J2me手机游戏存储玩家分数源码(6页珍藏版)》请在金锄头文库上搜索。

1、J2me 手机游戏存储玩家分数源码package shiyan23;import java.io.*;import javax.microedition.lcdui.*;import javax.microedition.rms.*;public class Displayable1 extends Form public Form form;/* Constructor */public TextField t1;public TextField t2;private RecordStore rs;private Display dis;public Displayable1(Display

2、 dis) super();this.dis=dis;this.form=this;try jbInit(); catch (Exception e) e.printStackTrace();/*Component initialization*/private void jbInit() throws Exception / Set up this Displayable to listen to command eventssetCommandListener(new CommandListener() public void commandAction(Command command,

3、Displayable displayable) this_commandPerformed(command, displayable););/ add the Exit commandaddCommand(new Command(Exit, Command.EXIT, 1); addCommand(new Command(存储, Command.SCREEN, 1);addCommand(new Command(高分榜, Command.SCREEN, 1);t1 = new TextField(游戏玩家, play1, 10, TextField.ANY);t2 = new TextFie

4、ld(当前分数, 0, 10, TextField.NUMERIC);append(t1);append(t2);/*Handle command events*/public void this_commandPerformed(Command command, Displayable displayable) /* todo Add command handling code */if (command.getCommandType() = Command.EXIT) / stop the MIDletMIDlet1.quitApp();if (command.getLabel().equ

5、als(存储) try rs=RecordStore.openRecordStore(shiyan23, true);ByteArrayOutputStream bo=new ByteArrayOutputStream();DataOutputStream dao = new DataOutputStream(bo);dao.writeUTF(t1.getString();dao.writeInt(Integer.parseInt(t2.getString();byte data=bo.toByteArray();rs.addRecord(data, 0, data.length); catc

6、h (Exception e) System.out.println(存储过程出现异常 );e.printStackTrace();finallytry rs.closeRecordStore();catch (RecordStoreException ex) if(command.getLabel().equals(高分榜)try rs=RecordStore.openRecordStore(shiyan23, true);myFilter mf=new myFilter(); MyComparator mc=new MyComparator();RecordEnumeration en=r

7、s.enumerateRecords(mf,mc,true);Form f=new Form(游戏高分榜);f.addCommand(new Command(返回, Command.BACK, 1);f.setCommandListener(new CommandListener() public void commandAction(Command command, Displayable displayable) dis.setCurrent(form); );f.append(姓名 分数);int i=0;while(en.hasNextElement()&(i=10000)return

8、 true;catch(Exception e )return false;class MyComparator implements RecordComparatorpublic int compare(byte rec1,byte rec2)int score1=0,score2=0;ByteArrayInputStream bis=new ByteArrayInputStream(rec1);DataInputStream dis=new DataInputStream(bis);trydis.readUTF();/获取昵称score1=dis.readInt();/获取分数catch(

9、Exception e )bis=new ByteArrayInputStream(rec2);dis=new DataInputStream(bis);trydis.readUTF();/获取昵称score2=dis.readInt();/获取分数catch(Exception e )if(score1=score2)return RecordComparator.EQUIVALENT;/ifif(score1score2)return RecordComparator.PRECEDES; else return RecordComparator.FOLLOWS;/elsepackage s

10、hiyan23;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;/* Title: * Description: * Copyright: Copyright (c) 2009* Company: * author not attributable* version 1.0*/public class MIDlet1 extends MIDlet static MIDlet1 instance;Display dis=Display.getDisplay(this);Displayable1 displa

11、yable = new Displayable1(dis);public MIDlet1() instance = this;public void startApp() Display.getDisplay(this).setCurrent(displayable);public void pauseApp() public void destroyApp(boolean unconditional) public static void quitApp() instance.destroyApp(true);instance.notifyDestroyed(); instance = null;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号