Multi-choice mode, multi-interface implementation, screen switching exercise

Source: Internet
Author: User

Package chapter04;

Import javax. microedition. lcdui. choice;
Import javax. microedition. lcdui. choicegroup;
Import javax. microedition. lcdui. Command;
Import javax. microedition. lcdui. commandlistener;
Import javax. microedition. lcdui. display;
Import javax. microedition. lcdui. displayable;
Import javax. microedition. lcdui. form;
Import javax. microedition. lcdui. item;
Import javax. microedition. lcdui. itemstatelistener;
Import javax. microedition. lcdui. textbox;
Import javax. microedition. MIDlet. MIDlet;
Import javax. microedition. MIDlet. midletstatechangeexception;
/*
* Author: jcuckoo
* Date: 2008-10-27
* Function: Multi-choice mode, multi-interface implementation, screen switching exercise
*/
Public class mulchoicegroupmidlet extends MIDlet implementsItemstatelistener, commandlistener{
Private display;
Private form;
Private textbox;
Private command exitcommand;
// Radio Mode
// Private choicegroup CG = new choicegroup ("Salary:", choice. Exclusive );
// Zero or multiple choice mode
Private choicegroup CG = new choicegroup ("wage level:", choice. Multiple );
// Pop-up mode
// Private choicegroup CG = new choicegroup ("wage level:", choice. Popup );
Public mulchoicegroupmidlet (){
Display = display. getdisplay (this );
Form = new form ("");

Textbox = new Textbox ("the selected content is:", "", 0 );
Exitcommand = new command ("return", command. screen, 1 );

// Add options to the CG component
CG. append ("less than 600", null );
CG. append ("600 ~ 1000 ", null );
CG. append ("3000 ~ 5000 ", null );
CG. insert (2, "1000 ~ 3000 ", null );

// Delete the specified option
// CG. Delete (1 );

// Delete all options
// CG. deleteall ();

// Add CG to form
Form. append (CG );

// Register a listener event
Form. setitemstatelistener (this );

// Add the exit button to textbox
Textbox. addcommand (exitcommand );


// Register a listener event
Textbox. setcommandlistener (this );

}

Protected void destroyapp (Boolean arg0) throws midletstatechangeexception {
}

Protected void pauseapp (){
}

Protected void Startapp () throws midletstatechangeexception {
Display. setcurrent (form );
}

 Public void itemstatechanged (item ){
String STR = "";

// Obtain the CG size of the component.
Int num = CG. Size ();
System. Out. println (Num );

// Create a Boolean array to store the statuses of the CG component.
Boolean [] status = new Boolean [num];

// Obtain the status of CG and put it in the status array.
CG. getselectedflags (Status );

// Cyclically display the content in the array
For (INT I = 0; I <num; I ++ ){
System. Out. println (status [I]);
}

// Obtain the content that is true (that is, the selected option) in the array.
For (INT I = 0; I <num; I ++ ){
If (status [I]) {
STR = STR + CG. getstring (I) + "/N ";
}
}

// Use textbox to display the corresponding content
Textbox. setstring (STR );

// Use the screen manager to switch the screen
Display. setcurrent (textbox );
 
}

 Public void commandaction (command C, displayable d ){
If (C = exitcommand ){


// Use the screen manager to switch the screen
Display. setcurrent (form );
}


}

}

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.