Programming

Cascaded List’s Menu in MIDlet

After fetching the Basics of J2ME programming language,this is my first attempt to create something using List’s,so I tried to cascade the list’s and the modal alert.

PROGRAM-2 : Creating Cascaded List’s menu in midlet.

Description: This program present’s you the showcase of How to cascade the multiple list’s in order to create hierarchial menu along with command buttons.

Instructions to run a file:
The sourcecode file has to saved as .java file in the /src folder of new project created using a software “Sun java wireless Toolkit 2.5.2 for CLDC” and for more details, feel free to ask here via comment’s.

Download Link: Creating_Lists [.txt file]

OUTPUT Snapshots:

Source Code: 

//the essential package's imported
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Travel extends MIDlet implements CommandListener
{
private Display d;
private List mlist,mlist1,mlist2,mlist3,mlist4;
private Command mExit,mNext,mBack;
private Alert alert1,alert2,alert3,alert4;
public Travel()
{
d=Display.getDisplay(this);
mlist=new List("TRAVEL LIST",List.IMPLICIT);
mlist.append("Aeroplane",null);
mlist.append("Car",null);
mlist.append("Train",null);
mlist.append("Hotel",null);
String str1[]={"KingFisher","JetGo","Spice","AirIndia"};
String str2[]={"Indigo","Santro","Skoda","Benz"};
String str3[]={"Mangla","Rajdhani","Deccan Queen","Sahyadri"};
String str4[]={"Taj","Grand Hyatt","Derby","President"};
mlist1=new List("Aeroplane LIST",List.IMPLICIT,str1,null);
mlist2=new List("Car LIST",List.IMPLICIT,str2,null);
mlist3=new List("Train LIST",List.IMPLICIT,str3,null);
mlist4=new List("Hotel LIST",List.IMPLICIT,str4,null);
mExit=new Command("EXIT",Command.EXIT,0);
mNext=new Command("NEXT",Command.SCREEN,1);
mBack=new Command("BACK",Command.BACK,1);
mlist.addCommand(mExit);
mlist.addCommand(mNext);
mlist.setCommandListener(this);
mlist1.addCommand(mBack);
mlist1.addCommand(mNext);
mlist1.setCommandListener(this);
mlist2.addCommand(mBack);
mlist2.addCommand(mNext);
mlist2.setCommandListener(this);
mlist3.addCommand(mBack);
mlist3.addCommand(mNext);
mlist3.setCommandListener(this);
mlist4.addCommand(mBack);
mlist4.addCommand(mNext);
mlist4.setCommandListener(this);
}
public void startApp()
{
d.setCurrent(mlist);
}
public void pauseApp()
{
}
public void destroyApp(boolean b)
{
}
public void commandAction(Command c,Displayable s)
{
if(c==mExit)
{
notifyDestroyed();
}
if (c==mNext || c==List.SELECT_COMMAND)
{
int index=mlist.getSelectedIndex();
if(index==0)
{d.setCurrent(mlist1);
int index1=mlist1.getSelectedIndex();
if (c==mNext)
{
alert1 =new Alert("OPTION SELECTED","U CHOSE "+mlist1.getString(index1),null,null);
alert1.setTimeout(Alert.FOREVER);
d.setCurrent(alert1);
}
}
if(index==1)
{d.setCurrent(mlist2);
if (c==mNext)
{
int index2=mlist2.getSelectedIndex();
alert2 =new Alert("OPTION SELECTED","U CHOSE "+mlist2.getString(index2),null,null);
alert2.setTimeout(Alert.FOREVER);
d.setCurrent(alert2);
}
}
if(index==2)
{d.setCurrent(mlist3);
if (c==mNext)
{
int index3=mlist3.getSelectedIndex();
alert3 =new Alert("OPTION SELECTED","U CHOSE "+mlist3.getString(index3),null,null);
alert3.setTimeout(Alert.FOREVER);
d.setCurrent(alert3);
}
}
if(index==3)
{d.setCurrent(mlist4);
if (c==mNext)
{
int index4=mlist4.getSelectedIndex();
alert4 =new Alert("OPTION SELECTED","U CHOSE "+mlist4.getString(index4),null,null);
alert4.setTimeout(Alert.FOREVER);
d.setCurrent(alert4);
}
}
}
if (c==mBack)
{
d.setCurrent(mlist);
}
}
}
view raw Travel.java hosted with ❤ by GitHub

One thought on “Cascaded List’s Menu in MIDlet”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.