/* this Midlet is designed to show an impplicit list with associated images and strings */ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class ImpList extends MIDlet implements CommandListener{ private Display myDisplay; // Reference to a display private List lsChoice; // Our List private Command cmExit; // Exit Command private Command cmAdd; // Add Command public ImpList(){ myDisplay = Display.getDisplay(this); // Create the commands cmExit = new Command("Exit", Command.EXIT, 1); cmAdd = new Command("Add", Command.SCREEN, 1); // Catch Exception Error try{ // create and array of image items Image images[] = {Image.createImage("/Resources/ff.png"), Image.createImage("/Resources/rew.png"), Image.createImage("/Resources/new.png")}; // Create array of Strings relating to images String selections[] = {"Next", "Previous", "New"}; // create List using arrays, add commands, Listen for events lsChoice = new List("Your Option:", List.IMPLICIT, selections, images); lsChoice.addCommand(cmExit); lsChoice.addCommand(cmAdd); lsChoice.setCommandListener(this); } catch (java.io.IOException e){ System.out.println("Unable to Find or Read .png file"); System.out.println("Check if the path to .png file is correct!"); } } // startApp public void startApp(){ myDisplay.setCurrent(lsChoice); } // pauseApp public void pauseApp(){ } // destroyApp public void destroyApp(boolean unconditional){ } // commandAction for event handling public void commandAction(Command c, Displayable s){ // check if an implicit list has generated an event if (c == List.SELECT_COMMAND){ switch (lsChoice.getSelectedIndex()) { // if the first choice in the list is selected send string "Next" // to consol case 0: System.out.println("Next"); break; // if the second choice in the list is selected send string // "Previous" to consol case 1: System.out.println("Previous"); break; // if the Third choice in the list is selected send string "New" // to consol case 2: System.out.println("New"); break; // set the default value to "New Task" default: System.out.println("New Task"); } } // Otherwise if Add command is chosen we add a new member in the list // called "Delete" else if (c == cmAdd){ // catch IO exception if application cannot find del.png try{ // Add a new member to the list using size() as the insertion point //the new member will append to the list lsChoice.insert(lsChoice.size(), "Delete", Image.createImage("/Resources/del.png")); } catch (java.io.IOException e) { System.err.println("Unable to find or read del.png file"); System.out.println("Make sure the path is correct!"); } } // otherwise if command is Exit then destroy application else if (c == cmExit){ destroyApp(false); notifyDestroyed(); } } }