I have recently been a J2ME project, some experience is shared with everyone. If you have insufficient or need to contact me, please send email to cqucyf@263.net.
The tools used in the project are J2MEWTK1.0.4_01 CodeWarrior. Because the project is not a game, there is no design to programming, and there is a summary of the following points:
1. Make the project name in Chinese. This is to let the project name in the mobile phone, the setting method is as follows: Open the appropriate item in J2MEWTK, "Set" - "" MIDLETS ", select your MIDlet, select Edit to modify.
2, network programming. Because the project involves network interaction, there is a network programming, and the experience of network programming has mainly 3 aspects:
2.1 Data transmission. There are many ways to send data in MIDP1.0, which mainly uses the HTTP protocol. code show as below:
Import javax.microedition.io. *;
......
String Url = "http://127.0.0.1/ts/login?username=a&password=a";
HTTPConnection HC = (httpConnection) Connector.Open (URL));
2.2 Reception of data. A lot of data receiving methods are provided in MIDP 1.0, but they need to be converted into arrays. This time this time is to write feedback information as head information. Write the information written in a certain format, and then the resolution is received. Such as:
String s = hc.getheaderfield ("login");
If the number of information returned when the query is not fixed, you can use one header to store the format of the return data, and then read the corresponding head sequentially. Such as:
String Temp = Hc.getHeaderfield ("Number"); // Number of returned information
If the information is in this format: "Data" digit, ie DATA1, DATA2 ..., etc. It can be read like this:
INT number = integer.parseint (TEMP);
String [] data = new string [number];
For (int i = 0; i { Data [i] = hc.getheaderfield ("Data" i); } // Resolution Data 2.3 Chinese issues in network transmission. This is divided into a Chinese issue and the process of receiving Chinese issues. Sending Chinese issues: Submit Chinese information to the server, including Chinese data in the URL, can solve this: give your own J2MEWTK1.0.4 to hit the Chinese supplement package, and then use the toString method to transform when sending. Such as: String s = "Chinese"; String Url = "http://127.0.0.1/ts/login?param=" S.toString (); HTTPConnection HC = (httpConnection) Connector.Open (URL)); Received Chinese Problem: The Chinese data that receives the server needs to decode, and the general decoding method: String Str; // STR Save the received server data Byte [] bytes = str.getbytes ("ISO8859_1"); String s = new string (bytes, "GB2312"); 3, MIDP1.0 supports limited support limited support, only supporting Vector. 4, there is another confusion question: Is it written in a class in a class? Is it written in each interface? There are many examples in J2MewTk to write all interfaces in a class, but this code is inconvenient for management. If you write multiple classes, you spend memory. It is really difficult to choose!