J2ME Learning Notes (III.)

Source: Internet
Author: User
Tags root directory
Notes from today I think I will have a long time will not involve real actual development, this period of time mainly concentrates on the basic learning

On Oh, will not go, I dare not run that? But mainly because there is no need to rush to make things for the brothers, so want to study hard. No

The code must still be written. After all, write code more quickly to learn ^_^

Oh, step-by-step to start the mobile phone development of the journey. I do not know whether I can insist on learning this piece, because the company's work pressure is also

Big. Usually there is no rest, weekends also have a lot of things to do. So it's also a very depressing aspect. Oh. Try to be good. One

The web is not the way, hehe, learn a little more maybe later. After all, handheld devices are a developing trend in the future.

When I was studying, I was using the sun's official MIDP example. You can go down on your own. I chose the midp_2.0 reference source.

Writing a midlet can be performed on the actual device or emulator requires the following steps:
1, write program code
2, compile
3, Advance Audit (preverify) This step is very important, because many classes of PCs installed on the J2SE support, but the actual J2ME does not support

Hold.
4, write the description of the document
5, the synthesis jar file
6, the test row wrong
7, in the simulator or physical machine running.

Ok


Let me start by writing a simple example of the final 7 steps that have been completed from the beginning of code writing. (This example is backed up with midp_2.)

Some of the already defined interfaces in 0, so I put this program in the MIDP root directory I unzipped: F:\MIDP. )

The first step is to write the code:

Import javax.microedition.midlet.*;
Import javax.microedition.lcdui.*;
public class Hellomidlet extends MIDlet implements commandlistener{
Private Command Exitcommand;
private display display;
Public Hellomidlet () {
display = Display.getdisplay (this);
Exitcommand = new Command ("Exit", Command.screen, 2);
}
public void startApp () {
TextBox t = new TextBox ("Hello MIDlet", "Test string", 256, 0);
T.addcommand (Exitcommand);
T.setcommandlistener (this);
Display.setcurrent (t);
}
public void Pauseapp () {}
public void Destroyapp (Boolean unconditional) {}
public void Commandaction (Command C, displayable s) {
if (c = = Exitcommand) {
Destroyapp (FALSE);
Notifydestroyed ();
}
}
}

Step two: Compile
I set up a Midjavac.bat file under the F:\MIDP that is designed to compile

Javac-g:none-classpath F:\midp\classes; -bootclasspath F:\midp\classes%1

-bootclasspath This parameter I am also used for the first time, should be the control compile-time control only use the established directory under the base class bar. Such as

If you do not use this parameter then it is possible that the program you are writing can run on a PC, but not on a MIDP-enabled handheld device.

Then go to F:\MIDP under DOS to run Midjavac Hellomidlet

Step three: Pre-audit
Similarly, I created a midver.bat file under F:\MIDP for pre-approval.

F:\midp\bin\preverify-classpath F:\midp\classes; -D%1%2

Go to the MIDP folder under DOS and run Midver test Hellomidlet
If the pre-trial nucleus is passed then a folder test will be established under F:\MIDP to put the pre-trial nucleus through class.

This time we actually write the program can be run on the simulator.

Fourth Step: Write the description document
FileName: Hellomidlet.jar
Midlet-name:helloworld
midlet-version:1.0.0
Midlet-vendor:sun Microsystems, Inc.
Midlet-description:sample Hello World MIDlet
midlet-info-url:http://java.sun.com/j2me/
Midlet-jar-url:http://127.0.0.1/hellomidlet.jar
midlet-jar-size:1020
microedition-profile:midp-1.0
microedition-configuration:cldc-1.0
MIDlet-1: HelloWorld, Hellomidlet

Fifth step: synthesizing jar files
Prepare a Midjar.bat file
Jar-cfm%1%2-c. \%3.
Run: Midjar hellomidlet.jar hellomidlet.jad Hellomidlet

Step Sixth: Test the wrong line
Write a Midjartest.bat file
F:\midp\bin\midp-classpath f:\midp\classes;%1-descriptor%2

Running in DOS: Midjartest Hellomidlet.jar Hellomidlet.jad
Oh, should see the operation of it?!
If you find Alert:error verifying class Hellomidlet
One of those mistakes is that your procedure is not subject to a pre-trial review. ^_^

The seventh step: Oh, if there are handheld devices on their own pass up to try to see slightly. If not, it will only run on the simulator. That's right

, you should not synthesize jar files if you run the session on the emulator.

Oh, in fact, these things are very basic, I can install a Nokia or Moto Simulator, and then only used on the JB mounted on the mobiles

ET, and then draw a plugin to get it done. I'm going to have to use this complicated (sweat ing. I'm a little impatient when I write.

To complete such a simple step, in fact, is to better understand the mobile phone program to complete the principle of it.



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.