Last active
December 22, 2015 22:09
-
-
Save demlaip/6538095 to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment