Using Java to write mobile apps--motorola Iden (1) (Turn)

Source: Internet
Author: User
Tags command line modify
Program Sen Wang
Institute of Science and Technology Management, Taiwan Jiaotong University
moli.mt88g@nctu.edu.tw


█ Preface
All the actions in this article are tested on the Windows 200 operating system. If you validate this article on a different platform, such as Windows 98 or Windows Me, we cannot guarantee that the same result will be available.
█ Introduction
At any time, we suddenly feel that everyone around us has a mobile phone. Using mobile phones to communicate with others has become a part of our lives. People in some of the most advanced countries in northern Europe can use their mobile phones to buy the goods sold by vending machines, and they can use mobile phones as a tool of authentication when engaging in business (m-commence) transactions. In Japan, many of the additional functions of mobile phones are part of the youth culture. The coming 3G, wireless broadband dream brings people to the future of wireless communication expectations.
Then, some manufacturers began marketing their own PDA, as if no PDA in hand, it is not like modern people. A wide variety of PDA flooded the market, best-selling and not selling, people are dazzled by confusion. There was a big problem--it was a lot of trouble to have our phones and PDAs at the same time--even if they were thin and short. Wouldn't it be more convenient to have a cell phone with a PDA? Then hear the consumer voice of the manufacturers, began to launch a mobile phone and PDA integrated products, from NOKIA 9000, Motorola A6188 (Taiji), to the recent launch of the Ericsson R380, NOKIA 9210, are mobile phone and PDA combination of examples, Although the price of the relationship, but these products are still many people dream of high order products.
Despite the combination of PDA and cell phone products appear, we still feel that there is insufficient, I think you must have found that the application is inadequate, although the phone and PDA combined, but these products on the PDA function seems to be dead. We can write the applications on these platforms on PalmOS, Windows CE, EPOC, and so on PDA, but never have the opportunity to download our written program to these mobile phones (even if some mobile PDA is also using EPOC, such as Ericsson R380).
I believe that the manufacturers also hear the voices of our engineers who like to write programs everywhere, so starting from the end of 2000, there will be a lot of support for Java mobile phone will soon be launched, of course, these manufacturers also provide a mobile phone development Program SDK, we can finally write small programs on the phone to amuse themselves! It's a dream I've been waiting for so long.
Mobile phone platform diversity and complexity, and PDA can be said to be even more, so we can know-ha! It's time for Java to come in handy. We all know the Java program that executes on the browser is called the applet, the Java program that executes on the PalmOS is called Spotlet, but the application that executes on the handset we call MIDlet, believe to everybody is a strange noun, This is also the main character to be introduced in this article.
Java-enabled handset manufacturers are currently known to have Nokia (which is expected to launch a Java-enabled mobile Nokia 9210 in early 2001), Motorola (will first support integrated Digital Enhanced Network (IDen) The mobile phone on the web supports Java and then launches a Java-enabled GSM phone, which will generally support Java 2002 years ago and the NTT DoCoMo (which will launch its Java-enabled handsets around the second quarter of next year).
Although these large companies are ready to support Java, in deciding to write this article, only Motorola will open its SDK to the Web site for the program developers to download the test, so this article is based on the Motorola J2ME SDK written. And because these phones are not available in the market, so our program is in the SDK contained in the simulator to execute, I believe that when the last of these mobile phones listed, we will write the midlet should be easily and successfully executed on Motorola's mobile phone.

█ How to get Motorola J2ME SDK
The first thing we have to do, of course, is to get the SDK first!
Please download Motorola J2ME SDK Drop 7 directly to https://commerce.motorola.com/idenonline/ideveloper/. If you are not a member of the Iden®developer, please register on the network (free of charge) first. After the registration is successful, Motorola sends the password to your email box and then uses that password to log in to my Development Center on the page. After entering, select the Tools & resources above the page to enter the Web page of the downloadable development tool, select Motorola J2ME SDK components Developer Edition, Drop 7.0 below the download hyperlink below contains the SDK, the entire SDK size is about 3 MB.
Please note that the download Page for Motorola j2me™sdk installation instructions before downloading will tell you the installation password, please write it down first. When you install the Motorola J2ME SDK on your computer later, you will be asked to install the password, so make sure you write down the password.

Installation of the █motorola J2ME SDK

    • Installation Requirements
      According to official requirements, the basic equipment for installing the Motorola J2ME SDK is:
      Pentium MHz microprocessor
      MB RAM
      Windows NT WorkStation 4.0 with service Pack 3/win98
      (This is a test on the Windows Professional Chinese version)
      Approximately 6 MB of hard disk space
      Java 2 SDK 1.2.2
      (This article uses the Java 2 SDK 1.3.0_01 for testing)

    • Install Motorola J2ME SDK
      Before installing the new Motorola J2ME SDK, make sure you have removed the old Motorola J2ME SDK completely. You can remove the old Motorola J2ME SDK from the "Add/Remove Programs" feature inside the console. The previous version of the Motorola J2ME SDK installation path is then cleared.
      To unlock the zip file you downloaded from the Motorola Web site, you will see a file named Motorola_sdk.exe, which you can double-click to start the installation action. Please note that the system will require you to enter a password at installation time, please enter the previously recorded installation password.

█motorola J2ME SDK Directory structure
After you successfully install the Motorola J2ME SDK, its directory structure is as follows:
Http://www.csdn.net/expert/wangsen/artic05.gif
Http://www.csdn.net/expert/wangsen/artic7.gif
█midlet Program Structure
On the phone to execute the program we collectively referred to as MIDlet, its program structure is very simple, and familiar with the applet structure is similar to the wonderful.
Each MIDlet program must inherit from the Javax.microedition.midlet.MIDlet category and implement three functions, respectively:

protected void startApp ()
protected void Pauseapp ()
protected void Destroyapp (Boolean unconditional)

The process of starting and ending a midlet program is shown in the following diagram:
Http://www.csdn.net/expert/wangsen/artic8.gif

█ Write and Compile MIDlet
Please go to your Motorola J2ME SDK installation directory under the Demo\midlets directory to create a new file named Hellomidlet.java, which reads:

Hellomidlet.java
Import javax.microedition.lcdui.*;
Import javax.microedition.midlet.*;

public class Hellomidlet extends MIDlet
{
Hellomidlet ()
{
}

protected void startApp () throws Midletstatechangeexception
{
}

protected void Pauseapp ()
{
}

protected void Destroyapp (Boolean unconditional)
Throws Midletstatechangeexception
{
}
}
In the Demo\midlets directory you will see a batch file called Compileall.bat that, in addition to helping you compile all of the enclosing sample programs, simplifies the compilation process of the MIDlet you write yourself.
In the Command Line window, enter: Compileall Hellomidlet.java
If you compile successfully, the results of the output on the screen are shown in the following illustration:
Http://www.csdn.net/expert/wangsen/artic08.jpg
From the on-screen output, you can see that for MIDlet to execute on the phone, there are generally two actions (similar to spotlet), namely, compilation (compiling) and pre-audit (preverifying).
Regarding the advance audit This action, the author already in run! PC November article " using Java to write PalmOS application Basics"Among the readers, if you have any questions about this, please send your run! PC November number to go over for a review!

From this brief midlet production process, I believe you can find that it is much simpler to write a spotlet that can be performed on a KVM than simply using Sun CLDC. The reason is that compileall.bat This batch file helps us to do most of the dirty work.
So, if you write a good program is not placed in the Demo\midlets directory, can not compile it? From the Compileall.bat, we can find it to help us to complete the two tasks of the instructions. If our written program is placed outside the Demo\midlets directory, you can perform the following instructions, and you can still successfully make MIDlet:
(Let's assume that your Motorola J2ME SDK is installed in the D:\MotoSDK directory and put your own Hellomidlet.java in the D:\jdk1.3.0_01\my directory.) We also assume that you execute the following instructions under the D:\jdk1.3.0_01\my directory. )
Compiling: javac-o-bootclasspath d:\MotoSDK\lib Hellomidlet.java Note:-bootclasspath points to the location of the class function library.
Pre-approval: D:\MotoSDK\bin\preverifier-classpath d:\MotoSDK\lib;. D. Hellomidlet Note:
1. -classpath point to where the class function library is located, and to the location where we wrote the MIDlet.
2. –d points to the path you want to place after the class file is generated, if you write "." Represents this directory, overwriting class files that were not previously compiled. If you do not specify, the default value is the. \output directory.
Of course, if you have trouble with your manual operation, you can copy the Compileall.bat to another directory and change the relevant settings for the compiler directive and the class function library in the pre-audit instructions.
Referring to Compileall.bat, by the way, explain to your readers that, as mentioned earlier, Compileall.bat can help you compile all the sample programs that are located in the Demo\midlets directory, just enter them directly under the column: CompileallCan. Compileall.bat will automatically have the following entries when you compile the package:
Com.mot.j2me.midlets.bounce
Com.mot.j2me.midlets.imagetests
Com.mot.j2me.midlets.paddleball
Com.mot.j2me.midlets.scribble
Com.mot.j2me.midlets.tests
Com.mot.j2me.midlets.tutorials
If you want Compileall.bat to automatically compile other package programs below, please open Compileall.bat and modify the settings of its Compileclass environment variables.

█ Modify and Execute MIDlet
After the program is written, the most desirable thing to do is to let it execute on the phone, but since we are unable to get Motorola's Java-enabled phones, we can only execute our midlet on the simulator enclosed in the Motorola J2ME SDK. Believe that when the mobile phone is officially launched, it should be able to execute smoothly on the phone. The following author will tell you how to test your midlet with the simulator enclosed in the Motorola J2ME SDK.
Before that, because the sample program we wrote before was simply a midlet shell, we had to let it display some information on the emulator, so modify the previous program example so that it reads as follows:
Hellomidlet.java
Import javax.microedition.lcdui.*;
Import javax.microedition.midlet.*;

public class Hellomidlet extends MIDlet
{
Private Display Firstdisplay;
Private Form Firstform;
Hellomidlet ()
{
Firstdisplay = Display.getdisplay (this);
Firstform = new Form ("Hello MIDlet");
Stringitem Firststritem = new Stringitem ("Hello", "MIDlet");
Firstform.append (Firststritem);
}

protected void startApp () throws Midletstatechangeexception
{
Firstdisplay.setcurrent (Firstform);
}

protected void Pauseapp ()
{
}

protected void Destroyapp (Boolean unconditional)
Throws Midletstatechangeexception
{
}
}
Please place this file in the \demo\midlets directory. After the compilation is complete, switch the directory to the Scripts subdirectory, where you will find some written batch files. Please execute these batch file directives under this directory to start the emulator. The instructions and execution results are as follows:

Instructions: Runemul Hellomidlet
Output results
Http://www.csdn.net/expert/wangsen/artic09.jpg
Instructions: runMotoi1000 Hellomidlet
Output results
Http://www.csdn.net/expert/wangsen/artic010.jpg
Instructions: Runmotoiden Hellomidlet
Output results
Http://www.csdn.net/expert/wangsen/artic011.jpg
Instructions: Runstartac Hellomidlet
Output results
Http://www.csdn.net/expert/wangsen/artic012.jpg
Instructions: Runmydevice Hellomidlet
Output results
Error Loading Property file:c:/properties/mydevice.props(The system cannot find the specified path.) The error message appears because you do not specify the appearance of the phone that belongs to the user, and later will teach you how to set the appearance of your customized phone.
If we place the written program outside the Demo\midlets directory, you can execute the following instructions and still be able to successfully launch the emulator and execute the MIDlet:
(Let's assume that your Motorola J2ME SDK is installed in the D:\MotoSDK directory and put your own Hellomidlet.java in the D:\jdk1.3.0_01\my directory.) We also assume that you execute the following instructions under the D:\jdk1.3.0_01\my directory. )

perform a generic emulator
Java-djava.library.path=d:\motosdk\lib
-classpath D:\motosdk\bin\emulator.jar;d:\motosdk\bin\configtool.jar Com.mot.tools.j2me.emulator.Emulator

-classpath.; D:\MotoSDK\lib Javax.microedition.midlet.AppManagerHellomidlet
-jsa 1 1
Please note:
The first-classpath is set and there is a space between the-classpath and the path name.
The second-classpath is set and there is no space between the-classpath and the path name.
execute emulator and apply i1000 phone appearance

Java-djava.library.path=d:\motosdk\lib
-classpath D:\motosdk\bin\emulator.jar;d:\motosdk\bin\configtool.jar Com.mot.tools.j2me.emulator.Emulator

-classpath.; D:\MotoSDK\lib
-devicefile Resources\motorolai1000.props
Javax.microedition.midlet.AppManager


Hellomidlet
-jsa 1 1

Please note:
The first-classpath is set and there is a space between the-classpath and the path name.
The second-classpath is set and there is no space between the-classpath and the path name.
execute emulator and apply Iden phone appearance
Java-djava.library.path=d:\motosdk\lib
-classpath D:\motosdk\bin\emulator.jar;d:\motosdk\bin\configtool.jar Com.mot.tools.j2me.emulator.Emulator

-classpath.; D:\MotoSDK\lib
-devicefile Resources\motorolaidenplatform.props
Javax.microedition.midlet.AppManager

Hellomidlet
-jsa 1 1


Please note:
The first-classpath is set and there is a space between the-classpath and the path name.
The second-classpath is set and there is no space between the-classpath and the path name.
execute emulator and apply StarTAC phone appearance
Java-djava.library.path=d:\motosdk\lib
-classpath D:\motosdk\bin\emulator.jar;d:\motosdk\bin\configtool.jar Com.mot.tools.j2me.emulator.Emulator

-classpath.; D:\MotoSDK\lib
-devicefile Resources\startac.props
Javax.microedition.midlet.AppManager

Hellomidlet
-jsa 1 1


Please note:
The first-classpath is set and there is a space between the-classpath and the path name.
The second-classpath is set and there is no space between the-classpath and the path name.
execute the simulator and apply the user's custom phone appearance
Java-djava.library.path=d:\motosdk\lib
-classpath D:\motosdk\bin\emulator.jar;d:\motosdk\bin\configtool.jar Com.mot.tools.j2me.emulator.Emulator

-classpath.; D:\MotoSDK\lib
-devicefile < The absolute path where your props files are located >javax.microedition.midlet.appmanager

Hellomidlet
-jsa 1 1


Please note:
The first-classpath is set and there is a space between the-classpath and the path name.
The second-classpath is set and there is no space between the-classpath and the path name.
If you place your props file under the D:\MotoSDK\bin Resources directory, the above instructions are changed to: -devicefile resources\< Your props file name >
Note that when you start the emulator directly using the instructions above, if you receive the following error message:
Error Loading Property file:resources/defaultdevice.props(The system cannot find the specified path.) )
This is because you did not copy the resources subdirectory under the D:\MotoSDK\bin directory to the D:\JDK1.3.0_01\my directory.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.