J2ME Learning Notes (v)

Source: Internet
Author: User
Note the beginning of the transaction processing must assume that a variety of different concepts, Java base class inheritance, and so on. So the feeling is very boring. To

When I was learning Java, I had a headache when I talked about business. Oh.
Oh, began to study the MIDlet transaction processing slightly. In fact, no applets have been written before, but the servlet is much more written,

After all, the role of the servlet in MVC is important. Any servlet must inherit Javax.servlet.http.HttpServle

T class, in fact as a midlet is also a concept, all MIDlet must inherit Javax.microedition.midlet.MID

Let In other words, it inherits the three methods of Startapp (), Pauseapp (), Destoryapp ().
When a midlet succeeds, it begins its lifecycle, and the lifecycle is fully JPM controlled. MIDlet

A midletstatechangeexception is thrown when a state transition occurs unexpectedly.
In the entire MIDP specification, transaction processing is divided into advanced transaction processing and low-level transaction processing. Low-level transaction processing based on different handheld devices

There will be different class library support, and there is no such limit for advanced transaction processing. In other words, if we do MIDlet want to be on different machines

Can be run we cannot invoke methods in low-level transactions, only using methods in advanced transaction processing.
Throughout MIDP, transaction processing is formed by a combination of transaction <-> processing methods.
MIDP all of the display-capable components inherit from the Displayable abstract class, and it also derives screen (processing of the higher office

and canvas (dealing with low-level transactions). MIDP senior transaction processing has two interfaces, namely Commandlistener and ITE

Mstatelistener. The Commandlistener interface is often used in conjunction with the command class in Javax.microedition.lcdui. OK

See the following example:
/**
* @author you Li
*
* CopyRight (C) 2005
*/
Import javax.microedition.midlet.*;
Import javax.microedition.lcdui.*;

public class Hleventmidlet extends MIDlet implements commandlistener{
Private Command Exitcommand;
Private Command Info1command;
Private Command Info2command;
private display display;
Public Hleventmidlet () {
display = Display.getdisplay (this);
Exitcommand = new Command ("Exit", command.screen,1);//The smaller the number, the priority

More high
Info1command = new Command ("Menu 1", command.screen,2);
Info2command = new Command ("Menu 2", command.screen,2);
}
public void startApp () {
TextBox t = new TextBox ("Hello", "Test ^_^", 256, 0); "
T.setcommandlistener (this);
T.addcommand (Exitcommand);
T.addcommand (Info2command);
T.addcommand (Info1command);
Display.setcurrent (t);
}
public void Pauseapp () {
}
public void Destroyapp (Boolean unconditional) {
}
public void Commandaction (Command C, displayable s)
{
if (c = = Exitcommand) {
Notifydestroyed ();
}else if (c = = Info1command) {
Notifydestroyed ();
}
}
}
After running, you will find that you have a simple menu to choose from! ^_^ Command defines 8 commands altogether, excellent

First level below from high to Low: Command.back
Command.cancel command.exit command.help Command.item Command.ok command.screen

Command.stop. Oh, I think it's no use to say so, write a little bit of code are clear. ^_^

Commandlistener uses the unicast mode, so only one transaction can be handled at the same time.

Then enjoy the Hazi Itemstatelistener interface. Like Commadnlistener, it also uses the unicast model.
Let's take a look first:
/**
* @author you Li
*
* CopyRight (C) 2005
*/
Import javax.microedition.midlet.*;
Import javax.microedition.lcdui.*;

public class Tfeventmidlet extends MIDlet implements Itemstatelistener {

/**
*
*/
private display display;
Public Tfeventmidlet () {
display = Display.getdisplay (this);
}
public void startApp ()
{
Form f = new form ("form");
TextField tf = new
TextField ("Input", "Origin", 25,textfield.any);
F.append (TF);
F.setitemstatelistener (this);
Display.setcurrent (f);
}
public void Pauseapp () {
}
public void Destroyapp (Boolean unconditional) {
}
public void Itemstatechanged (item) {
TextField tmp = (TextField) item;
Tmp.setstring ("Changed");
}

}
The specific use of these two interfaces I do not want to have to write out, according to the interface required to inherit the class A look I would like to also

All the same. Oh, the name is still very normative.



According to the MIDP specification, if Commandlistener and Itemstatelistener are processed simultaneously, itemstatechanged () takes precedence over Comm

Andaction () processing.

Advanced transaction processing is very simple, but the function does not really meet the requirements of our development. So this time we're going to

With the help of low-level transactions.

I don't want to see it today. More tired, hehe, so the low-level transaction processing tomorrow evening to study well.




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.