}} 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(); }