0

The above code gives no errors and the emulator starts running, but the Login Screen is not being displayed on the emulator.
I am working in j2me sdk 3.0.
Anyone please tell me why it isnt showing the Login Screen.

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("sandeep") && password.equals("sandeep")) {
      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());
    } 
  }
}

Edited by peter_budo: Please do not use CODE SNIPPED option to post question. Use FORUM THREAD!

5
Contributors
4
Replies
9
Views
8 Years
Discussion Span
Last Post by _neo_
0

try dis hope it helps u

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("/1.png");
imge = Image.createImage("/2.png");
img2 = Image.createImage("/3.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("max99") && password.equals("1234")) {
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 e, Displayable d) {
String label = e.getLabel();
if(label.equals("Cancel")) {
destroyApp(true);
} else if(label.equals("Login")) {
validateUser(userName.getString(), password.getString());
}
}
}

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

0

why doesnt the progrm wrk crrctly of i exclude the img cmds..my code is as follows:

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class LoginExamples extends MIDlet implements CommandListener{
  private Display display;
  private TextField userName,password;
  public Form form;
  private Command login,cancel;
 
  public LoginExamples() {
  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);
  }
 
  public void startApp() 
  {
  display = Display.getDisplay(this);
  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("sandeep") && password.equals("sandeep")) 
  {
  showMsg();
  } else {
  tryAgain();
  }
  }  
  public void showMsg() {

  Alert success = new Alert("Login Successfully Your Login Process is completed!",AlertType.INFO);
  userName.setString("");
  password.setString("");
  display.setCurrent(success, form);  
  }

  public void tryAgain() {
  Alert error = new Alert("Login Incorrect Please try again",AlertType.ERROR);
  error.setTimeout(900);
  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());
  } 
  }
}

but this doesnt seem to work..is it necessary to include the image cmds?

Edited by peter_budo: Keep It Clear - Do use code tags when posting any code

0

In first and second codes class name were LoginExample.
In last snippet it is LoginExamples. Have you changed your project properties for LoginExample"S" ???

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.