J2ME development of information, is indeed very few, generally recommended to the novice is Mr. Sen Wang's "PDA and mobile phone development," a book, however, the book is not really suitable for the new reading, the book's first few chapters spent a lot of time to explain the command line debugging J2ME procedures and a lot of points, in fact, these things, As a primary J2ME developer, there is absolutely no need to learn and master, but only to add a lot of burden to themselves. Now do J2ME development, most have the IDE (integrated development environment), such as Jb,eclipse what, even with the simplest WTK, also do not need to carry out path configuration and other operations, so beginners can completely skip these content, direct use. I think, do program development, emphasis on practical experience, rather than theoretical research, so the new person can be directly from the J2ME program flow, direct access, and do not need to understand too many basic concepts, such as what is the API, what is MIDP, what is JDK and so on. These things I am not very clear to now, but does not affect my development, I am fastidious pragmatism, therefore, the keynote of this article is to tell some practical development methods. In addition, first of all to declare: This article in all development and commissioning is in the WTK environment, please readers attention.
A Learning the basics of J2ME needs J2ME itself is part of the Java language, therefore, a certain understanding of the Java language is necessary, and the Java language itself is a language of object-oriented programming, so the concepts of classes and objects need to be understood, and these are not introduced in this article. In addition, the introduction to the API in this article is very brief, so readers should consult the relevant content in the API.
Two Brief introduction of J2ME development environment J2ME development environment as described above, there are currently jb,eclipse,wtk three ways, of which the first two are integrated development environment, the programming is more convenient, intelligent association and other functions, and WTK relatively only to provide manual compilation and packaging, And there is no debug feature. But WTK does not need redundant configuration, to all kinds of simulator can say is Plug and Play, and the program directory under WTK is concise and simple, convenient inquiry. These several development environment each has the long shortcoming, therefore everybody may own choice, but for the novice, still recommends uses the WTK, because just contacts J2ME development, rather spends the time in the disposition, is not better than spends in the programming.
Three J2ME program Flow I feel that every language has its own fixed format, as with the writing of several elements of the article, always have the beginning, the end and so on. To understand the format of a language, is to learn the language first to grasp the content. If the process is compared to a pipeline project, then each language has a pipe entrance, in the J2ME, this entrance is the MIDlet class, this class is also called the J2ME main class, each program, has one or more fixed main class, here, we only talk about the general situation, That is, there is only one MIDlet main class situation, as you can see from the API, MIDlet class has several fixed methods, startApp (), Pauseapp (), Destroyapp (), these methods are like piping works (in the following story, I have compared programming to a number of key valves in the pipeline project, a J2ME program to start after the first experience of MIDlet construction method, and then enter the Startapp () method, when there is a special case hangs, will enter the Pauseapp method, when the program is over, Exit through the Destroyapp method. A J2ME program can have no other class, but cannot have MIDlet class, as long as there is a complete main class, is a complete J2ME program. For example, a very fine canon of "HelloWorld", there is only one midlet.
I think, J2ME is actually a very standard sequential process language, J2ME no real multithreading, in many cases, a J2ME program running, we can all of his process to complete tracking. This is very convenient for debugging. Here also to explain that in the J2ME program, the screen object is a relatively important object, all of your operations, you want to express the meaning, all need to be depicted on the screen, so the screen operation is also the most basic and most important one operation, therefore, The operation of the J2ME program is to control the objects on display and display displayable (including Form,textbox,list,canvas and so on). In other words, let the program display the required displayable on the screen when it is appropriate. The method that is used is the Display.setcurrent () method.
On the screen object's operation, I want to explain that the J2ME default screen has only one, that is, the current screen, all of which operate on the current screen, so that when you set a Canvas object to the current screen in the main class, the main class is already off screen. Objects that are off screen cannot be manipulated directly. This point needs to be noted. All outside operations can only be used for displayable objects displayed on the current screen, either form,list, or canvas. In this case, the operation of the screen-off class can only be done through static methods or an instance of the class. One of the simplest game processes in J2ME is this: a main class and a canvas class, where the main class entry defines a canvas object, and the canvas object inherits a runnable interface and then defines a thread based on this object. The canvas object is then set to the current screen object, and the thread starts, that is, the thread's start () method, the canvas run method starts running, and the Run method usually uses the repaint () method to brush the screen, so the process is to press paint ()- >run->paint () ... Such a process reciprocating, if there are keyboard input, then keypressed () and other methods are interspersed in the middle. Basically J2ME program is to follow such process to walk, so in the development and debugging as long as the necessary tracking of this process can be.