⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listtest.java

📁 大量j2me源代码
💻 JAVA
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * A demonstration of a List screen.
 * @author Martin J. Wells
 */
public class ListTest extends MIDlet implements CommandListener
{
   private Form form;
   private Command quit;
   private Command add;
   private Command back;
   private Command go;
   private List list;

   /**
    * Constructor for the MIDlet which creates a List Screen and appends
    * a bunch of items on the list as well as a Form containing an Add
    * and Quit command.
    */
   public ListTest()
   {
      // Setup the UI
      String[] choices = { "I", "and", "you", "love", "hate",
                           "kiss", "bananas", "monkeys", "that" };

      list = new List("Choices", List.IMPLICIT, choices, null);
      go = new Command("Go", Command.OK, 1);
      back = new Command("Back", Command.BACK, 2);
      list.addCommand(go);
      list.addCommand(back);
      list.setCommandListener(this);

      // build the form
      form = new Form("Make-a-Story");
      add = new Command("Add", Command.SCREEN, 1);
      quit = new Command("Quit", Command.EXIT, 2);
      form.addCommand(add);
      form.addCommand(quit);
      form.setCommandListener(this);
   }

   /**
    * Called by the Application Manager when the MIDlet is starting or resuming
    * after being paused. In this example it acquires the current Display object
    * and uses it to set the Form object created in the MIDlet constructor as
    * the active Screen to display.
    * @throws MIDletStateChangeException
    */
   protected void startApp() throws MIDletStateChangeException
   {
      Display.getDisplay(this).setCurrent(form);
   }

   /**
    * Called by the MID's Application Manager to pause the MIDlet. A good
    * example of this is when the user receives an incoming phone call whilst
    * playing your game. When they're done the Application Manager will call
    * startApp to resume. For this example we don't need to do anything.
    */
   protected void pauseApp()
   {
   }

   /**
    * Called by the MID's Application Manager when the MIDlet is about to
    * be destroyed (removed from memory). You should take this as an opportunity
    * to clear up any resources and save the game. For this example we don't
    * need to do anything.
    * @param unconditional if false you have the option of throwing a
    * MIDletStateChangeException to abort the destruction process.
    * @throws MIDletStateChangeException
    */
   protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
   {
   }

   /**
    * The CommandListener interface method called when the user executes a
    * Command. This method handles the standard quit command as well as an add
    * command which triggers the display to be switched to the list. It then
    * handles commands from the list screen to either select an item or abort.
    * @param command the command that was triggered
    * @param displayable the displayable on which the event occurred
    */
   public void commandAction(Command command, Displayable displayable)
   {
      System.out.println("commandAction(" + command + ", " + displayable +
                         ") called.");
      try
      {
         // form handling
         if (displayable == form)
         {
            if (command == quit)
            {
               destroyApp(true);
               notifyDestroyed();
            }

            if (command == add)
            {
               Display.getDisplay(this).setCurrent(list);
            }
         }

         // list handling
         if (displayable == list)
         {
            if (command == go)
            {
               form.append(list.getString(list.getSelectedIndex()) + " ");
               Display.getDisplay(this).setCurrent(form);
            }

            if (command == back)
               Display.getDisplay(this).setCurrent(form);
         }

      }

      catch (MIDletStateChangeException me)
      {
         System.out.println(me + " caught.");
      }
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -