Study Notes on j2-based learning platform (7)

Source: Internet
Author: User

The Development of Mobile Phone programs will certainly involve graphics processing issues. Like transaction processing, MIDP processes the graphic interface

It is also divided into advanced graphic interface processing and low-level graphic interface processing. Similarly, the advanced graphic interface can be used to conveniently move values,

Limited Functions and powerful low-level graphic interface, but some code may need to be changed after the value is moved. All advanced graphic interfaces must be inherited.

While the low-level graphic interface inherits the canvas and uses the graphic processing methods defined by graphics in large quantities. Figure used by MIDP

The interface classes all belong to the javax. microedition. lcdui package used in the previous code. At the same time (only the same

Time) only one subclass of canvas and scree can exist.
The screen class has four subclasses: Alert, list, Textbox, and form. Form is an element that does not have any interfaces,

It is just a container that can accommodate other item classes in which it is used to combine a complex graphic user interface. The other sub-classes belong

It encapsulates a predefined Fixed graphic interface and can only be used separately. This is actually the relationship between various input boxes and forms in HTML.

Same.
Like other development languages, you can test the usage of these sub-classes one by one. Pai_^ use the actual program

Description of the relationship and the difference between the two.
I. List
1) choice. Implicit

Package com. graph;

/**
* @ Author you li
*
* Copyright (c) 2005
*/
Import javax. microedition. lcdui .*;
Import javax. microedition. MIDlet .*;

Public class implisttest extends MIDlet implements commandlistener {

Private display;
Public implisttest (){

// Todo automatically generates the constructor stub
Display = display. getdisplay (this );
}

Protected void Startapp () throws midletstatechangeexception {
// Todo automatically generates method stubs
List alist = new list ("listtest", choice. implicit );
Alist. append ("A", null );
Alist. append ("B", null );
Alist. append ("C", null );
Alist. append ("D", null );
Alist. setcommandlistener (this );
Display. setcurrent (alist );
}

Protected void pauseapp (){
// Todo automatically generates method stubs

}

Protected void destroyapp (Boolean arg0) throws midletstatechangeexception {
// Todo automatically generates method stubs

}

Public void commandaction (command, displayable display ){
// Todo automatically generates method stubs
System. Out. println ("command action start ......");
If (command = List. select_command ){
List test = (list) display;
Int selected = test. getselectedindex ();
System. Out. println ("item" + selected + "selected ");
}
}

}

When we run this program, we will find four options on the screen and promise the indexid of the selected options. We can see that

Choice. Implicit option is selected, it will immediately use the setcommandlistener () method to register the content, and call comma

Dnaction () method. At the same time, the first parameter of the commadnaction () method is used to determine whether the choice. Implicit option is used.

2) choice. Exclusive

Package com. graph;

/**
* @ Author you li
*
* Copyright (c) 2005
*/
Import javax. microedition. MIDlet .*;
Import javax. microedition. lcdui .*;

Public class exclisttest extends MIDlet implements commandlistener {

Private display;
Command commit;
Public exclisttest (){
// Todo automatically generates the constructor stub
Display = display. getdisplay (this );
}

Protected void Startapp () throws midletstatechangeexception {
// Todo automatically generates method stubs
Commit = new command ("Submit", command. screen, 1 );
List alist = new list ("listtest", choice. Exclusive );
Alist. append ("A", null );
Alist. append ("B", null );
Alist. append ("C", null );
Alist. addcommand (COMMIT );
Alist. setcommandlistener (this );
Display. setcurrent (alist );
}

Protected void pauseapp (){
// Todo automatically generates method stubs

}

Protected void destroyapp (Boolean arg0) throws midletstatechangeexception {
// Todo automatically generates method stubs

}

Public void commandaction (command, displayable display ){
// Todo automatically generates method stubs
System. Out. println ("commadn action start ......");
If (command = commit ){
List TMP = (list) display;
Int selected = TMP. getselectedindex ();
System. Out. println ("item" + selected + "selected ");
}
}
}

Run this program and we will find the difference between choice. Exclusive and choice. implicit. Choice. Exclusive No

The commandaction () method will be run immediately after we select it. We can only use the commit System option menu to complete the final commit.

After you Click Commit in the system menu, the commandaction () method is executed.

3) choice. Multiple

/**
* @ Author you li
*
* Copyright (c) 2005
*/
Import javax. microedition. MIDlet .*;
Import javax. microedition. lcdui .*;

Public class multlisttest extends MIDlet implements commandlistener {

Private display;
Command commit;
 
Public multlisttest (){
Display = display. getdisplay (this );
}

Protected void Startapp () throws midletstatechangeexception {
// Todo automatically generates method stubs
Commit = new command ("Submit", command. screen, 1 );
List alist = new list ("listtest", choice. Multiple );
Alist. append ("A", null );
Alist. append ("B", null );
Alist. append ("C", null );
Alist. addcommand (COMMIT );
Alist. setcommandlistener (this );
Display. setcurrent (alist );
}

Protected void pauseapp (){
// Todo automatically generates method stubs

}

Protected void destroyapp (Boolean arg0) throws midletstatechangeexception {
// Todo automatically generates method stubs

}

Public void commandaction (command, displayable display ){
// Todo automatically generates method stubs
System. Out. println ("commadn action start ......");
If (command = commit ){
List TMP = (list) display;
Int num = TMP. Size ();
For (INT I = 0; I <num; I ++ ){
If (TMP. isselected (I )){
System. Out. println ("item" + I + "selected ");
}
}
}
}

}

In this program, we use choice. Multiple, that is, the use of multiple selection boxes. Like choice. Exclusive, only when

The commandaction () method is called after the system menu commit is used for the operation.

Ii. Alert and alerttype
Windows, and the general dialog box on the page is too much. This alert actually serves this purpose. It belongs to the subclass of screen,

We can use the setcurrent () method to display it on the screen. Of course, when alert sets to feed the screen, the system

There must be a picture. Otherwise, alert will throw an error because it cannot jump back. If we feed the alert object to set its ALER

The tType attribute alerttype. Alarm, alert. Forever will be returned from the alert window after we click the system validation key.

Start window. A simple example is as follows:
The alerttype. Alarm and alert. Forever attributes are set only when the "window" is displayed. Therefore, you need to click "done"

Then the alert object will be closed.

Package com. graph;

/**
* @ Author you li
*
* Copyright (c) 2005 www.iguess.com.cn
*/
Import javax. microedition. MIDlet .*;
Import javax. microedition. lcdui .*;

Public class alerttest extends MIDlet implements commandlistener {

Private display;
Command commit;
 
Public alerttest (){
Display = display. getdisplay (this );
}

Protected void Startapp () throws midletstatechangeexception {
// Todo automatically generates method stubs
List alist = new list ("listtest", choice. implicit );
Alist. append ("window", null );
Alist. append ("OK", null );
Alist. append ("error", null );
Alist. append ("info", null );
Alist. append ("warning", null );
Alist. setcommandlistener (this );
Display. setcurrent (alist );
}

Protected void pauseapp (){
// Todo automatically generates method stubs

}

Protected void destroyapp (Boolean arg0) throws midletstatechangeexception {
// Todo automatically generates method stubs

}
Public void commandaction (command, displayable dis ){
If (command = List. select_command ){
Alert = new alert ("window test ");
List temp = (list) DIS;
Switch (temp. getselectedindex ()){
Case 0:
Alert. settype (alerttype. Alarm );
Alert. setstring ("window ");
Alert. setTimeout (alert. Forever );
Display. setcurrent (alert );
Break;
Case 1:
Alert. settype (alerttype. Confirmation );
Alert. setstring ("OK ");
Display. setcurrent (alert );
Break;
Case 2:
Alert. settype (alerttype. Error );
Alert. setstring ("error ");
Display. setcurrent (alert );
Break;
Case 3:
Alert. settype (alerttype. info );
Alert. setstring ("info ");
Display. setcurrent (alert );
Break;
Case 4:
Alert. settype (alerttype. Warning );
Alert. setstring ("warning ");
Display. setcurrent (alert );
Break;
}
}
}
}

Am... Go to bed and watch TV on time .. Well, we have been waiting in front of the computer for dinner since this morning.

.. My eyes hurt .. Alas... Work is done for the boss, and money is also returned to the country, that is, the body is your own.

. Programmer .. It's just TMD .... Take a rest .. You can't finish learning...

========================================================== ====
I hope you can leave a message and discuss it more. The collision of ideas will spark. Also, the basic knowledge of me is almost finished.

Prepare for several mini-games .. If the middleware platform intends to work together, please send me an email. Sinoly@gmail.com

, Tell me your MSN, I will add ^_^...

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.