📄 mainmidlet.java
字号:
package junwei;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.util.Vector;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.*;
import rms.*;
/**
* 主程序入口MIDlet
* 一些公用变量、过程
* @author hong
*
*/
public class MainMidlet extends MIDlet {
//rms表名
final public static String RMS_BREED="breed";
final public static String RMS_PAGE="page";
final public static String RMS_MENU="menu";
final public static String RMS_TASTE="taste";
final public static String RMS_SYSINFO="sysinfo";
final public static String RMS_BACKREASON="backReason";
//全局变量
public static String PDAID="";
public static String posID="";
public static String posName="";
public static String areaID="";
public static String areaName="";
public static String serverLink="";
public static String glbUserID;
public static String glbUserNo;
public static String glbUserName;
public static boolean islogin=false;
public static Vector menus=new Vector();
public MainMidlet() {
Navigator.display=Display.getDisplay(this);
Navigator.midlet=this;
init();
}
protected void startApp() throws MIDletStateChangeException {
Navigator.current=Navigator.LOGIN_SCREEN;
// Navigator.current=Navigator.ADDMENU_SCREEN;
Navigator.show(null);
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
//获取本地初始化信息
private void init(){
RecordEnumeration re;
RecordStore rs;
rs = RMSUtil.openRSAnymay(RMS_SYSINFO);
if (rs != null) {
try {
re = rs.enumerateRecords(null, null, false);
if (re.hasNextElement()) {
byte[] data=re.nextRecord();
ByteArrayInputStream byteInStream = new ByteArrayInputStream(data);
DataInputStream inStream = new DataInputStream(byteInStream);
PDAID=inStream.readUTF();
inStream.close();
byteInStream.close();
}
rs.closeRecordStore();
GetDataThread t = new GetDataThread();
t.init(GetDataThread.rt_PDA);
t.start();
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
rs = RMSUtil.openRSAnymay(RMS_MENU);
if (rs != null) {
try {
re = rs.enumerateRecords(null, null, false);
menus.removeAllElements();
while (re.hasNextElement()) {
byte[] data = re.nextRecord();
menus.addElement(Menu.decode(data));
}
rs.closeRecordStore();
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
sortMenus(menus);
}
}
/**
* 根据输入字符串和指定分隔符进行分隔
*
* @param inputStr
* @return 分割后的字符串数组
*/
public static String[] splitString(String inputStr, char split) {
Vector tmp = new Vector();
int beginIndex = 0, endIndex;
try {
endIndex = inputStr.indexOf(split, beginIndex);
boolean over = false;
while (!over) {
if (endIndex == -1)
endIndex = inputStr.length();
tmp.addElement(inputStr.substring(beginIndex, endIndex));
beginIndex = endIndex + 1;
if (beginIndex < inputStr.length())
endIndex = inputStr.indexOf(split, beginIndex);
else
over = true;
}
if (inputStr.endsWith(String.valueOf(split)))
tmp.addElement("");
String[] result = new String[tmp.size()];
for (int i = 0; i < tmp.size(); i++)
result[i] = tmp.elementAt(i).toString();
return result;
} catch (Exception e) {
System.out.println("数据转换发生错误:" + inputStr);
return null;
}
}
/**
* 返回指定长度的字符串(后面补空,或截断)
*/
public static String getLenStr(String inputStr,int len){
if (inputStr.length()>=len){
return inputStr.substring(0,len);
}
else{
char[] result=new char[len];
for (int i=0;i<len;i++){
if (i<inputStr.length())
result[i]=inputStr.charAt(i);
else
result[i]=' ';
}
return String.valueOf(result);
}
}
/**
* 按编号排列菜品
* @param menus
*/
public static void sortMenus(Vector menus){
Menu menu_a,menu_b;
for (int i=0;i<menus.size();i++)
for (int j=i;j<menus.size();j++){
menu_a=(Menu)(menus.elementAt(i));
menu_b=(Menu)(menus.elementAt(j));
if (Integer.parseInt(menu_a.getMenuId())>
Integer.parseInt(menu_b.getMenuId())){
menus.setElementAt(menu_b,i);
menus.setElementAt(menu_a,j);
}
}
}
/**
* 获得某一类的菜品列表
* @param breedID 菜品类别
* @return 某一类的菜品列表
*/
public static Vector getMenusByBreed(String breedID){
Vector result=new Vector();
Menu aMenu;
for (int i=0;i<menus.size();i++){
aMenu=(Menu)(menus.elementAt(i));
if (aMenu.getBreedId().equals(breedID))
result.addElement(menus.elementAt(i));
}
return result;
}
public static Menu getMenu(String menuID){
Menu aMenu, selectMenu = null;
for (int i = 0; i < MainMidlet.menus.size(); i++) {
aMenu = (Menu) (MainMidlet.menus.elementAt(i));
if (aMenu.getMenuId().equals(menuID)) {
selectMenu = aMenu;
break;
}
}
return selectMenu;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -