您好,欢迎来到99网。
搜索
您的当前位置:首页游戏得分排行榜的代码

游戏得分排行榜的代码

来源:99网


import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet;

import javax.microedition.midlet.MIDletStateChangeException;

public class PhoneMIDlet extends MIDlet { Display display; private WelcomeCanvas wc; private PhoneList pl; private AddForm af; public PhoneMIDlet() { super(); wc = new WelcomeCanvas(this); pl = new PhoneList(this); af = new AddForm(this); } protected void startApp() throws MIDletStateChangeException { if(display == null) { display = Display.getDisplay(this); this.changeInterface(\"WelcomeCanvas\"); } } protected void pauseApp() { // TODO Auto-generated method stub } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { // TODO Auto-generated method stub } public void changeInterface(String str) { if(str.equals(\"WelcomeCanvas\")){ display.setCurrent(wc); }else if(str.equals(\"PhoneList\")){

// 更新界面 pl.deleteAll(); pl.loadPhones(); display.setCurrent(pl); }else if(str.equals(\"AddForm\")){ display.setCurrent(af); } } }

import java.util.Vector;

import javax.microedition.rms.InvalidRecordIDException; import javax.microedition.rms.RecordEnumeration; import javax.microedition.rms.RecordStore;

import javax.microedition.rms.RecordStoreException; import javax.microedition.rms.RecordStoreFullException;

import javax.microedition.rms.RecordStoreNotFoundException; import javax.microedition.rms.RecordStoreNotOpenException;

public class RMSOpe { private String storeName; private RecordStore rs; public RMSOpe(String storeName) { super(); this.storeName = storeName; } public void openRecordStore() {

try { rs = RecordStore.openRecordStore(storeName,true); } catch (RecordStoreFullException e) { e.printStackTrace(); } catch (RecordStoreNotFoundException e) { e.printStackTrace(); } catch (RecordStoreException e) { e.printStackTrace(); } } public void addPhone(String name,String phone) { String info = name+\":\"+phone; byte[] b = info.getBytes(); try { rs.addRecord(b,0,b.length); } catch (RecordStoreNotOpenException e) { e.printStackTrace(); } catch (RecordStoreFullException e) { e.printStackTrace(); } catch (RecordStoreException e) { e.printStackTrace(); } } //当删除某个ID的内容后,再添加再删除,会抛出InvalidRecordIDException,如何解决??? public void deletePhone(String str) { try { int lastId = rs.getNextRecordID(); for(int i=1;i }

} catch (RecordStoreException e) { e.printStackTrace(); } }

public Vector getAllPhone() { Vector v = new Vector(); try { RecordEnumeration re = rs.enumerateRecords(null,null,false); while(re.hasNextElement()) { v.addElement(new String(re.nextRecord())); } } catch (RecordStoreNotOpenException e) { e.printStackTrace(); } catch (InvalidRecordIDException e) { e.printStackTrace(); } catch (RecordStoreException e) { e.printStackTrace(); } return v; }

public void closeRecordStore() { try { rs.closeRecordStore(); } catch (RecordStoreNotOpenException e) { e.printStackTrace(); } catch (RecordStoreException e) { e.printStackTrace(); } }

import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Command;

import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Font;

import javax.microedition.midlet.MIDletStateChangeException;

public class WelcomeCanvas extends Canvas implements CommandListener{ private Command cmdPhone = new Command(\"排行榜\ private Command cmdExit = new Command(\"退出\ private PhoneMIDlet phoneMIDlet; public WelcomeCanvas(PhoneMIDlet phoneMIDlet) { super(); this.phoneMIDlet = phoneMIDlet; this.addCommand(cmdPhone); this.addCommand(cmdExit); this.setCommandListener(this); } protected void paint(Graphics g) { //清屏 g.setColor(0x00ffff); g.fillRect(0,0,this.getWidth(),this.getHeight()); String str = \"Welcom!\\n 排行榜\"; g.setFont(Font.getFont(Font.FACE_SYSTEM,Font.STYLE_BOLD,Font.SIZE_LARGE));; g.setColor(255,0,0); g.drawString(str,this.getWidth()/2,50,Graphics.HCENTER|Graphics.TOP); } public void commandAction(Command c, Displayable d) { if(c == cmdPhone) {

this.phoneMIDlet.changeInterface(\"PhoneList\"); }else if(c == cmdExit) { try { this.phoneMIDlet.destroyApp(false); } catch (MIDletStateChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); } this.phoneMIDlet.notifyDestroyed(); } } }

import javax.microedition.lcdui.Command;

import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Item; import javax.microedition.lcdui.TextField;

public class AddForm extends Form implements CommandListener{ private PhoneMIDlet pm; private Command cmdOK = new Command(\"确定添加\ private Command cmdBack = new Command(\"返回\ private TextField tfName = new TextField(\"请输入账号\ private TextField tfPhone = new TextField(\"请输入\ public AddForm(PhoneMIDlet pm)

得分

}

{ super(\"添加记录\"); this.pm = pm; this.addCommand(cmdOK); this.addCommand(cmdBack); this.setCommandListener(this); this.append(tfName); this.append(tfPhone); }

public AddForm(String arg0) { super(arg0); }

public AddForm(String arg0, Item[] arg1) { super(arg0, arg1); }

public void commandAction(Command c, Displayable d) { if(c == cmdOK)//添加记录,并回到记录界面 { //...... 添加记录 this.addPhone(); //返回到主界面 this.pm.changeInterface(\"PhoneList\"); }else if(c == cmdBack)//返回电话本界面 { this.pm.changeInterface(\"PhoneList\"); } }

/*添加记录*/

public void addPhone() { RMSOpe rms = new RMSOpe(\"PhoneStore\"); rms.openRecordStore(); rms.addPhone(tfName.getString(),tfPhone.getString()); rms.closeRecordStore(); }

import java.util.Vector;

import javax.microedition.lcdui.Command;

import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.List;

public class PhoneList extends List implements CommandListener{ private Command cmdBack = new Command(\"返回\ private Command cmdAdd = new Command(\"添加记录\ private Command cmdDel = new Command(\"删除记录\ private PhoneMIDlet pm; RMSOpe rms; Vector v; public PhoneList(PhoneMIDlet pm) { super(\"排行榜\ this.pm = pm; this.addCommand(cmdBack); this.addCommand(cmdAdd); this.addCommand(cmdDel); this.setCommandListener(this); rms = new RMSOpe(\"PhoneStore\"); v = new Vector(); } public PhoneList(String arg0, int arg1) { super(arg0, arg1); } public PhoneList(String arg0, int arg1, String[] arg2, Image[] arg3) { super(arg0, arg1, arg2, arg3); } public void commandAction(Command c, Displayable d) { if(c == cmdBack)//返回分数界面 { this.pm.changeInterface(\"WelcomeCanvas\"); }else if(c == cmdAdd) { this.pm .changeInterface(\"AddForm\");

}

}else if(c == cmdDel) { //删除记录... this.deletePhone(); //更新界面 this.pm.changeInterface(\"PhoneList\"); } }

/*载入所有成绩*/

public void loadPhones() { rms.openRecordStore(); v = rms.getAllPhone(); for(int i=0;i/*删除成绩*/

public void deletePhone() { rms.openRecordStore(); rms.deletePhone(this.getString(this.getSelectedIndex())); rms.deletePhone((String)v.elementAt(this.getSelectedIndex())); rms.closeRecordStore(); }

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 99spj.com 版权所有 湘ICP备2022005869号-5

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务