import javax.microedition.lcdui.*; import javax.microedition.rms.*; public class Editor implements CommandListener{ Display display; Editor instance; App app; File f; TextBox box; String name; public Command edit; public Command back; public Command ok; public Command help; public Command save; public Command translate; public Command menu; public int refer; public Editor(Display dip){ instance = this; display = dip; app = new App("str"); box = new TextBox(" "," ",5000,TextField.ANY); edit = new Command("Edit", Command.EXIT, 0); ok = new Command("Ok",Command.SCREEN, 1); help = new Command("Help",Command.SCREEN,1); f = new File(); back = new Command("Back",Command.EXIT, 1); translate = new Command("Translate",Command.SCREEN,1); save = new Command("Save",Command.SCREEN,1); menu = new Command("Menu",Command.SCREEN,0); app.addCommand(help); app.addCommand(edit); app.addCommand(translate); app.addCommand(save); app.addCommand(menu); box.addCommand(back); box.addCommand(ok); } public void EditFile(String name, String s, int refer, boolean create){ this.name = name; this.refer = refer; if (create) { if (refer == 0) s = f.read("/mdl/app.mdl"); if (refer == 1) s = f.read("/mdl/unit.mdl"); } app.setString(s); app.setCommandListener(instance); display.setCurrent(app); } public void edit(String old, String current, String next){ box.setString(current); box.setCommandListener(instance); display.setCurrent(box); } public void Continue(){ app.setString(app.old().concat(app.edit()).concat(app.next())); display.setCurrent(app); } public void save(){ String string = app.old().concat(app.edit()).concat(app.next()); String path = "file:///e:/"; String source ="source/"; try { RecordStore r = RecordStore.openRecordStore("settings",false); path = new String(r.getRecord(0)); source =new String(r.getRecord(1)); r.closeRecordStore(); }catch (Exception e){ e.printStackTrace(); } File f = new File(); f.writeFile(path.concat(source).concat(name).concat(".sdx"), string); } public void commandAction(Command c, Displayable d){ if (d == app) { if (c == save) { save(); } if (c == edit){ String old = app.old(); String edit = app.edit(); String next = app.next(); edit(old, edit, next); } } if (c == menu) Main.midlet.menuShow(); if (c == help) Main.midlet.aboutMenu(true); if (display.getCurrent() == box){ if (c == ok){ app.setString(app.old()+box.getString()+app.next()); display.setCurrent(app); } if (c == back) {app.setString(app.old() +app.edit() +app.next() ); display.setCurrent(app);} } } // end }