扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
static App instance; Display disp_; MIDlet app_; public static void createInstance(MIDlet app) { if(instance==null) instance=new App(); instance.app_=app; instance.disp_=Display.getDisplay(app); } private App() {} |
public static String getProperty(String name) { return instance.app_.getAppProperty(name); } public static Display getDisplay() { return instance.disp_; } |
public static void setCurrent(Displayable d) { if(d!=instance.old_) { instance.old_=instance.disp_.getCurrent(); instance.disp_.setCurrent(d); } } |
public static void restore() { if(instance.old_!=null) { instance.disp_.setCurrent(instance.old_); instance.old_=null; } } |
public static boolean restart() { if(instance.paused_) { instance.disp_.setCurrent(instance.bef_); instance.paused_=false; return true; } else return false; } public static void pause() { instance.bef_=instance.disp_.getCurrent(); instance.paused_=true; } public static void exit() { instance.app_.notifyDestroyed(); } public static void handleError(String msg, Exception ex) { System.out.println(msg+"::"+ex); } |
class LanguageMenu extends List implements CommandListener { Command cmdOK_; Object[] langlist_=new Object[]{ "Chinese","zh_cn",null, "USA","en_us",null}; public LanguageMenu() { super("Select Language",List.IMPLICIT); for(int i=0;i { this.append((String)langlist_[i],(Image)langlist_[i+2]); } cmdOK_=new Command("OK",Command.SCREEN,2); this.addCommand(cmdOK_); this.setSelectCommand(cmdOK_); this.setCommandListener(this); } public void commandAction(Command c, Displayable d) { if(c==cmdOK_) { ...... } } } |
public interface IApp { public void start(); } |
static void continueRun() { if(instance.app_ instanceof IApp) { ((IApp)instance.app_).start(); } } |
class LanguageMenu extends List implements CommandListener { Command cmdOK_; Object[] langlist_=new Object[]{ "Chinese","zh_cn",null, "USA","en_us",null }; public LanguageMenu() { super("Select Language",List.IMPLICIT); for(int i=0;i { this.append((String)langlist_[i],(Image)langlist_[i+2]); } cmdOK_=new Command("OK",Command.SCREEN,2); this.addCommand(cmdOK_); this.setSelectCommand(cmdOK_); this.setCommandListener(this); } public void commandAction(Command c, Displayable d) { if(c==cmdOK_) { int cmd=this.getSelectedIndex(); instance.lang_=(String)langlist_[cmd*3+1]; try { RecordStore.deleteRecordStore(LanguageRMS); } catch(Exception ex) {} try { RecordStore rs=RecordStore.openRecordStore(LanguageRMS,true); byte[] buf=instance.lang_.getBytes(); rs.addRecord(buf,0,buf.length); rs.closeRecordStore(); } catch(Exception ex) {} continueRun(); } } } |
public static boolean selectLanguage() { boolean r=(instance.lang_!=null); if(!r) { try { RecordStore rs=RecordStore.openRecordStore(LanguageRMS,true); RecordEnumeration e=rs.enumerateRecords(null,null,false); if(e.hasNextElement()) { instance.lang_=new String(e.nextRecord()); r=true; } else { r=false; } rs.closeRecordStore(); } catch(Exception ex) { r=false; } if(!r) { App.setCurrent(instance.new LanguageMenu()); } } return r; } |
public TestSM() { App.createInstance(this); } protected void startApp() throws MIDletStateChangeException { if(App.selectLanguage() && !App.restart()) { start(); } } public void start() { SM.getInstance(App.getLanguage()).load("1"); App.setCurrent(new TestCanvas()); } protected void pauseApp() { App.pause(); } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者