i write code for a mobile application like a tour guide..
i had create 5 class for this application, KutaBeachDictionary MIDlet class, ListMainMenu List class, ListMenuHotel List class, HotelDes01 Form class and the last Hotel class that store all information.
the problem is, i have [choose] variable in ListMenuHotel that contain getSelectedIndex() value, i want to take [choose] value from ListMenuHotel class to [index] variable in HotelDes01, so it determine the name of hotel that will display in form.but the index always 0 although i had choosen different menu from ListMenuHotel..
here is all code
in MIDlet class
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
public class KutaBeachDictionary extends MIDlet {
public KutaBeachDictionary() {
lstMenuUtama = new ListMenuUtama(this);
lstMenuHotel = new ListMenuHotel(this);
htlDes1 = new HotelDes01(this);
frmLoading = new FormLoading(this);
}
public Display getDisplay() {
return Display.getDisplay(this);
}
public void exitMIDlet() {
switchDisplayable(null, null);
destroyApp(true);
notifyDestroyed();
}
public void startApp() {
if (midletPaused) {
resumeMIDlet();
} else {
initialize();
startMIDlet();
}
midletPaused = false;
getDisplay().setCurrent(frmLoading);
new Thread(frmLoading).start();
frmLoading.done = false;
frmLoading.gLoading.setValue(0);
}
public void pauseApp() {
midletPaused = true;
}
public void destroyApp(boolean unconditional) {
}
private boolean midletPaused = false;
public ListMenuHotel lstMenuHotel;
public ListMenuRestaurant lstMenuRestaurant;
ListMenuUtama lstMenuUtama;
FormAbout frmAbout;
public HotelDes01 htlDes1;
FormLoading frmLoading;
}
the code in ListMenuHotel
import java.io.IOException;
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.lcdui.Ticker;
public class ListMenuHotel extends List implements CommandListener {
Hotel objHotel = new Hotel();
ListMenuHotel(KutaBeachDictionary run) {
super("List Hotel", List.IMPLICIT);
this.run = run;
try {
btnImage = Image.createImage("/btnImage.png");
} catch (IOException e) {
}
tickerMenu = new Ticker("Daftar Hotel di Pantai Kuta Bali");
setTicker(tickerMenu);
for (int i = 0; i < objHotel.namaHotels.length; i++) {
append(objHotel.namaHotels[i], btnImage);
}
addCommand(new Command("Select", Command.OK, 0));
addCommand(new Command("Back", Command.BACK, 0));
setCommandListener(this);
}
public void commandAction(Command cmd, Displayable dsp) {
if (cmd == SELECT_COMMAND) {
choose = getSelectedIndex();
Display.getDisplay(run).setCurrent(run.htlDes1);
}
switch (cmd.getCommandType()) {
case Command.BACK:
Display.getDisplay(run).setCurrent(run.lstMenuUtama);
break;
}
}
public int getChoose() {return choose;}
private KutaBeachDictionary run;
private Image btnImage;
private Ticker tickerMenu;
private int choose;
}
the code in HotelDes01 Form class
import java.io.IOException;
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.Image;
import javax.microedition.lcdui.ImageItem;
public class HotelDes01 extends Form implements CommandListener {
private KutaBeachDictionary run;
private int index;
private Hotel isiHotel = new Hotel();
public HotelDes01(KutaBeachDictionary run) {
super("Inna Kuta Hotel");
index = run.lstMenuHotel.getChoose(); //here is the problem..the value remain 0 althought i choose another??!!
this.run = run;
Image imgHotel = null;
String namaHotel = "\n" + isiHotel.namaHotels[index] + "\n";
try {
imgHotel = Image.createImage("/HotelImage/interface/htlDes1.png");
} catch (IOException e) {
}
append(new ImageItem(null, imgHotel, ImageItem.LAYOUT_CENTER, null));
append(namaHotel);
addCommand(new Command("Back", Command.BACK, 0));
setCommandListener(this);
}
public void commandAction(Command cmd, Displayable dsp) {
switch (cmd.getCommandType()) {
case Command.BACK:
Display.getDisplay(run).setCurrent(run.lstMenuHotel);
break;
}
}
}
can someone fix the code,, i had tried so many ways,,but completely failure.. T_T
This post has been edited by demongill: 22 March 2010 - 08:53 AM

New Topic/Question
Reply


MultiQuote


|