import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import parsing.Parser; import parsing.ParsingException; public class Main extends MIDlet implements CommandListener { public TextField code = new TextField("Code:", new String(), 500, TextField.ANY); public Form console = new Form("Console:"); public Command ok, back, exit; public Display display; public String codeToParse; public void startApp() { if(display==null) initApp(); } public void initApp(){ try{ display = Display.getDisplay(this); code = new TextField("Code: ", new String(), 500, TextField.ANY); ok = new Command("Ok", Command.OK, 0); exit = new Command("Exit", Command.EXIT, 0); console = new Form("Console: "); console.append(code); console.addCommand(ok); console.addCommand(back); console.setCommandListener(this); display.setCurrent(console); }catch(Throwable t){ Alert a = new Alert(t.toString(), t.getMessage(), null, null); a.setTimeout(5000); Display.getDisplay(this).setCurrent(a); a = null; System.gc(); } } public void pauseApp() { } public void commandAction(Command c, Displayable d){ if(c==ok){ try{ if(code.getString().toCharArray().length<1){ throw new ParsingException("null input"); } codeToParse = code.getString(); Parser parser = new Parser(codeToParse); String s = parser.parse(); Form log = new Form("Log:"); log.append(s); log.addCommand(back); log.setCommandListener(this); display.setCurrent(log); log = null; System.gc(); }catch(Throwable t){ Alert a = new Alert(t.toString(), t.getMessage(), null, null); a.setTimeout(50000); display.setCurrent(a); display.setCurrent(console); } }else if(c==exit){ destroyApp(true); }else if(c==back){ display.setCurrent(console); } } public void destroyApp(boolean unconditional) { if(unconditional){ console = null; ok = null; back = null; exit = null; code = null; codeToParse = null; display = null; System.gc(); notifyDestroyed(); } } }