Hi there
i m new to GUI programming and i have started it from midlet. the problem is, i have made separate classes for each page/form that is to be displayed on a mobile screen but dont know how to link them.
Like i want when my login successful, my mobile screen should move to list menu, and when i select a list menu, it should move to another screen, i have made separate classes for each intended screen.
Both the code of the classes i have pasted.
Anyone please help soon.
Thanks in advance.

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;

public class LoginExample extends MIDlet implements CommandListener{
  private Display display;
  private TextField userName,password;
  public Form form;
  private Command login,cancel;
  private Image img, imge, img2;

  public LoginExample() {
    form = new Form("Sign in");
    userName = new TextField("LoginID:", "", 30, TextField.ANY);
    password = new TextField("Password:", "", 30, TextField.PASSWORD);
    cancel = new Command("Cancel", Command.CANCEL, 2);
    login = new Command("Login", Command.OK, 2);
    try{
      img = Image.createImage("/logo.png");
      imge = Image.createImage("/front_left1_bad.png");
      img2 = Image.createImage("/Congratulations-1.png");
    }catch(Exception e){
      System.out.println(e.getMessage());
    }
  }

   public void startApp() {
    display = Display.getDisplay(this);
    try{form.append(img);}catch(Exception e){}
    form.append(userName);
    form.append(password);
    form.addCommand(cancel);
    form.addCommand(login);
    form.setCommandListener(this);
    display.setCurrent(form);
  }

  public void pauseApp() {}

  public void destroyApp(boolean unconditional) {
    notifyDestroyed();
  }

  public void validateUser(String name, String password) {
    if (name.equals("abdullah") && password.equals("abdullah")) {
      showMsg();
    } else {
      tryAgain();
    }
  }

  public void showMsg() {
    Alert success = new Alert("Login Successfully",
    "Your Login Process is completed!",
     img2, AlertType.INFO);
    success.setImage(img2);
    userName.setString("");
    password.setString("");
    display.setCurrent(success, form);

  }

  public void tryAgain() {
    Alert error = new Alert("Login Incorrect", "Please     try again", imge, AlertType.ERROR);
    error.setTimeout(900);
    error.setImage(imge);
    userName.setString("");
    password.setString("");
    display.setCurrent(error, form);
  }

  public void commandAction(Command c, Displayable d) {
    String label = c.getLabel();
    if(label.equals("Cancel")) {
      destroyApp(true);
    } else if(label.equals("Login")) {
      validateUser(userName.getString(), password.getString());
          ExclusiveChoiceList obj3 = new ExclusiveChoiceList();
    obj3.startApp();
    }
  }
  
}
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ExclusiveChoiceList extends MIDlet{
  private Display display;
  private List list;

  public ExclusiveChoiceList() {
    list = new List("Port Management System", Choice.EXCLUSIVE);
  }

  public void startApp(){
    display = Display.getDisplay(this);
    list.append("Vessels", null);
    list.append("Cargo", null);
    list.append("Fleets", null);
//    list.append("Chak De..", null);
//    list.append("Hum Aapke Hain Kaun", null);
    display.setCurrent(list);
  }

    public void pauseApp() {}

    public void destroyApp(boolean unconditional){
    notifyDestroyed();
  }
}

Recommended Answers

All 2 Replies

Only one class can extend MIDlet, other classes can receive it only as parameter. What you did above is as if you create two classes with main method and try pass parameters from each other (which possible, but requires other things). Besides, only one MIDlet can be running at any time, any other is either put to sleep or stopped...

sorry, way too late. It was urgent, so your reply was not timely.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.