Package de.esoco.j2me.midlet

Source Code of de.esoco.j2me.midlet.TestMidlet

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// J2ME-Lib source file
// Copyright (c) 2006 Elmar Sonnenschein / esoco GmbH
// Last Change: 27.10.2006 by eso
//
// J2ME-Lib is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 2.1 of the License, or (at your option)
// any later version.
//
// J2ME-Lib is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
// A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with J2ME-Lib; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA or use the contact
// information from the GNU website http://www.gnu.org
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package de.esoco.j2me.midlet;

import de.esoco.j2me.ui.ExecutableCommand;
import de.esoco.j2me.ui.ProgressView;
import de.esoco.j2me.ui.ScreenManager;
import de.esoco.j2me.util.Executable;
import de.esoco.j2me.util.UserNotificationException;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;


/********************************************************************
* Test MIDlet for J2ME-Lib.
*
* @author eso
*/
public class TestMidlet extends BasicMidlet implements CommandListener
{
  //~ Constructors -----------------------------------------------------------

  /***************************************
   * Constructor.
   */
  public TestMidlet()
  {
  }

  //~ Methods ----------------------------------------------------------------

  /***************************************
   * Process commands.
   *
   * @see CommandListener#commandAction(Command, Displayable)
   */
  public void commandAction(Command rCmd, Displayable rTarget)
  {
    try
    {
      if (rCmd instanceof Executable)
      {
        ((Executable) rCmd).execute(null);
      }
    }
    catch (Exception e)
    {
      // catch all Exceptions to prevent program termination
      recoverableError(e);
    }
  }

  /***************************************
   * Return a screen for the application start.
   *
   * @see BasicMidlet#getStartScreen()
   */
  protected Displayable getStartScreen()
  {
    return new Form("Test MIDlet");
  }

  /***************************************
   * Initialization.
   *
   * @throws UserNotificationException
   */
  protected void init() throws UserNotificationException
  {
  }

  /***************************************
   * Implemented from BasicMidlet to run the application.
   */
  protected void runApp()
  {
    Form aForm = new Form("Test");

    aForm.append("Testinfo");
    aForm.setCommandListener(this);

    aForm.addCommand(new ExecutableCommand("Quit", Command.EXIT, 99)
      {
        public void execute(Object rArg)
        {
          queryQuitApp();
        }
      });
    aForm.addCommand(new ExecutableCommand("Test Progress View",
                         Command.SCREEN, 1)
      {
        public void execute(Object rArg)
        {
          testProgressView();
        }
      });

    ScreenManager.show(aForm);
  }

  /***************************************
   * Tests the progress view feature.
   */
  protected void testProgressView()
  {
    final ProgressView aProgress = new ProgressView("Progress", null,
                            "Testing", true);

    new Thread()
      {
        public void run()
        {
          aProgress.init(500, "Dummy steps...");

          int nCount = aProgress.getMaximum();

          while (nCount-- > 0)
          {
            try
            {
              sleep(10);
            }
            catch (InterruptedException e)
            {
            }
            aProgress.advance(1);
          }
        }
      }.start();
  }
}
TOP

Related Classes of de.esoco.j2me.midlet.TestMidlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.