Use cases for Java me-list controls

Source: Internet
Author: User

/**
* Java me-list Control usage case
*/
Package com.xushouwei.cn;

Import java.io.IOException;
Import Javax.microedition.lcdui.Choice;
Import Javax.microedition.lcdui.Command;
Import Javax.microedition.lcdui.CommandListener;
Import Javax.microedition.lcdui.Display;
Import javax.microedition.lcdui.Displayable;
Import Javax.microedition.lcdui.Image;
Import javax.microedition.lcdui.List;
Import Javax.microedition.midlet.MIDlet;
Import javax.microedition.midlet.MIDletStateChangeException;
public class Listdemo extends MIDlet implements commandlistener{
Define two types of events
Private final static Command cmd_exit=new command ("EXIT", command.exit,1);
Private final static Command Cmd_back=new command ("Back", Command.back, 1);
Defining Display Objects
private display display;
Private List mainlist;
Private List execlusivelist;
Private List implicitlist;
Private List multiplelist;
Private Boolean firsttime;
Public Listdemo ()
{
Display=display.getdisplay (this);
string[] stringarray={"option A", "option B", "option C", "option D"};
Image[] Imagearray=null;
Execlusivelist=new List ("Exclusive", Choice.exclusive,stringarray, Imagearray);
Execlusivelist.addcommand (Cmd_back);
Execlusivelist.addcommand (Cmd_exit);
Execlusivelist.setcommandlistener (this);

Implicitlist=new List ("Implicit", Choice.implicit,stringarray, Imagearray);
Implicitlist.addcommand (Cmd_back);
Implicitlist.addcommand (Cmd_exit);
Implicitlist.setcommandlistener (this);

Multiplelist=new List ("multiple", Choice.multiple,stringarray, Imagearray);
Multiplelist.addcommand (Cmd_back);
Multiplelist.addcommand (Cmd_exit);
Multiplelist.setcommandlistener (this);

Firsttime=true;
}

public void Commandaction (Command C, displayable D) {
TODO auto-generated Method Stub
if (D.equals (mainlist)) {
if (C==list.select_command)
{
if (D.equals (mainlist))
{
Switch ((List) d). Getselectedindex ())
{
Case 0:
Display.setcurrent (execlusivelist);
Break
Case 1:
Display.setcurrent (implicitlist);
Break
Case 2:
Display.setcurrent (multiplelist);
Break
}
}
}

}
Else
{
if (C==cmd_back)
{
Display.setcurrent (mainlist);
}
}
if (c==cmd_exit)
{
try {
Destroyapp (FALSE);
} catch (Midletstatechangeexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
Notifydestroyed ();
}

}

protected void Destroyapp (Boolean arg0) throws Midletstatechangeexception {
TODO auto-generated Method Stub

}

protected void Pauseapp () {
TODO auto-generated Method Stub

}

protected void startApp () throws Midletstatechangeexception {
TODO auto-generated Method Stub
Image[] Imagearray=null;
if (firsttime)
{

try {
Image icon=image.createimage ("Images/icon.png");
Imagearray=new Image[]{icon,icon,icon};
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
String[] stringarray={"Exclusive", "implicit", "multiple"};
Mainlist=new List ("Choose type", Choice.implicit,stringarray,imagearray);
Mainlist.addcommand (Cmd_exit);
Mainlist.setcommandlistener (this);
Display.setcurrent (mainlist);
Firsttime=false;
}

}

Use cases for Java me-list controls

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.