import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class MobileGUI_Menu extends MIDlet implements CommandListener
{
Display display;
List menuList;
List inboxList;
List outboxList;
List draftList;
List sentList;
TextBox inputBox;
Alert alert = new Alert("Error", "Error loading menu (images)", null, AlertType.ERROR);
static final Command okCommand = new Command("OK",Command.OK,1);
static final Command backCommand = new Command("Back",Command.BACK,0);
static final Command exitCommand = new Command("Exit", Command.STOP, 2);
String currentMenu;
public MobileGUI_Menu()
{
}
public void startApp() throws MIDletStateChangeException
{
display = Display.getDisplay(this);
menuList = new List("Messaging", Choice.IMPLICIT);
try
{
menuList.append(" Write Message ", Image.createImage("/icon.png"));
menuList.append(" Inbox ", Image.createImage("/icon.png"));
menuList.append(" Outbox ", Image.createImage("/icon.png"));
menuList.append(" Drafts ", Image.createImage("/icon.png"));
menuList.append(" Sent Messages ", Image.createImage("/icon.png"));
menuList.addCommand(exitCommand);
menuList.setCommandListener(this);
display.setCurrent(menuList);
currentMenu = "Main";
} catch (Exception e)
{
showalert();
destroyApp(true);
}
}
void mainMenu()
{
display.setCurrent(menuList);
currentMenu = "Main";
}
public void pauseApp() {
display = null;
menuList = null;
inboxList = null;
outboxList = null;
draftList = null;
sentList = null;
}
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
public void showWriteForm()
{
inputBox = new TextBox ("Enter the Your Message", "", 160, TextField.ANY);
inputBox.addCommand(backCommand);
inputBox.setCommandListener(this);
inputBox.setString("");
display.setCurrent(inputBox);
currentMenu = "Write";
}
public void showInboxForm()
{
inboxList = new List("Inbox", Choice.IMPLICIT);
inboxList.append("Inbox 1 ", null);
inboxList.append("Inbox 2 ", null);
inboxList.append("Inbox 3 ", null);
inboxList.addCommand(backCommand);
inboxList.setCommandListener(this);
display.setCurrent(inboxList);
currentMenu = "Inbox";
}
public void showOutboxForm()
{
outboxList = new List("Outbox", Choice.IMPLICIT);
outboxList.append("Outbox 1 ", null);
outboxList.append("Outbox 2 ", null);
outboxList.append("Outbox 3 ", null);
outboxList.addCommand(backCommand);
outboxList.setCommandListener(this);
display.setCurrent(outboxList);
currentMenu = "Outbox";
}
public void showDraftForm()
{
draftList = new List("Drafts", Choice.IMPLICIT);
draftList.append("Draft 1 ", null);
draftList.append("Draft 2 ", null);
draftList.append("Draft 3 ", null);
draftList.addCommand(backCommand);
draftList.setCommandListener(this);
display.setCurrent(draftList);
currentMenu = "Draft";
}
public void showSentForm()
{
sentList = new List("Sent Messages", Choice.IMPLICIT);
sentList.append("Messages 1 ", null);
sentList.append("Messages 2 ", null);
sentList.append("Messages 3 ", null);
sentList.addCommand(backCommand);
sentList.setCommandListener(this);
display.setCurrent(sentList);
currentMenu = "Sent";
}
public void showalert()
{
try
{
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
catch(Exception e) {}
}
public void commandAction(Command c, Displayable d)
{
try
{
String label = c.getLabel();
if (label.equals("Done"))
{
destroyApp(true);
}
if (label.equals("Exit"))
{
destroyApp(true);
}
else if (label.equals("Back"))
{
mainMenu();
}
else
{
if (label.equals("Back") && currentMenu.equals("Write")) {
mainMenu();
}
if (label.equals("OK") && currentMenu.equals("Inbox")) {
mainMenu();
}
if (label.equals("OK") && currentMenu.equals("Outbox")) {
mainMenu();
}
if (label.equals("OK") && currentMenu.equals("Draft")) {
mainMenu();
}
if (label.equals("OK") && currentMenu.equals("Sent")) {
mainMenu();
}
List down = (List)display.getCurrent();
switch(down.getSelectedIndex())
{
case 0: showWriteForm();break;
case 1: showInboxForm();break;
case 2: showOutboxForm();break;
case 3: showDraftForm();break;
case 4: showSentForm();break;
}
}
}
catch(Exception e) {}
}
}