// En MIDlet med en textruta som har flera kommandon import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class LostUppgift extends MIDlet implements CommandListener { private Display displayen; private TextBox textrutan; private TextBox hjälprutan; private Command exitkommandot; private Command trippkommandot; private Command trappkommandot; private Command trullkommandot; private Command hjälpkommandot; private Command hjälpOKkommandot; public LostUppgift() { } public void destroyApp(boolean unconditional) { } public void pauseApp() { } public void startApp() { textrutan = new TextBox("Hej!", "Hej, världen!", 20, 0); hjälprutan = new TextBox("Instruktioner", "Tryck på knapparna och var glad.", 100, 0); exitkommandot = new Command("Exit", Command.EXIT, 0); trippkommandot = new Command("Tripp", Command.SCREEN, 0); trappkommandot = new Command("Trapp", Command.SCREEN, 0); trullkommandot = new Command("Trull", Command.SCREEN, 0); hjälpkommandot = new Command("Hjälp", Command.SCREEN, 0); hjälpOKkommandot = new Command("Tillbaka", Command.BACK, 0); textrutan.addCommand(exitkommandot); textrutan.addCommand(trippkommandot); textrutan.addCommand(trappkommandot); textrutan.addCommand(trullkommandot); textrutan.addCommand(hjälpkommandot); textrutan.setCommandListener(this); hjälprutan.addCommand(hjälpOKkommandot); hjälprutan.setCommandListener(this); displayen = Display.getDisplay(this); displayen.setCurrent(textrutan); } public void commandAction(Command c, Displayable s) { if (c == exitkommandot) notifyDestroyed(); else if (c == trippkommandot) textrutan.setString("Du tryckte på Tripp!"); else if (c == trappkommandot) textrutan.setString("Du tryckte på Trapp!"); else if (c == trullkommandot) textrutan.setString("Du tryckte på Trull!"); else if (c == hjälpkommandot) displayen.setCurrent(hjälprutan); else if (c == hjälpOKkommandot) displayen.setCurrent(textrutan); } }