akuvidz 0 Newbie Poster

what is wrong with my code ?

package PSM;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;

import java.io.*;


public class LoginGUI extends Form implements ItemStateListener,ItemCommandListener,CommandListener {

    private Display display;
    private Command exit,save;
    private Login midlet;
    private StringItem login;
    private TextField username,password;


    public LoginGUI(Login midlet, Display display) {
        // TODO Auto-generated constructor stub
        super("Login Screen");
        this.display = display;
        this.midlet = midlet;
        exit = new Command("Exit",Command.EXIT,3);
        save = new Command("Login",Command.SCREEN,1);
        username = new TextField("Username","",255,TextField.ANY);
        this.append(username);
        password = new TextField("Password","",255,TextField.PASSWORD);
        this.append(password);

        this.addCommand(exit);

        login = new StringItem(null,"Login",Item.BUTTON);
        login.setDefaultCommand(save);
        login.setItemCommandListener(this);
        append(login);
        setItemStateListener(this);


    }

    public void commandAction(Command c, Displayable d) {




    }

    public void itemStateChanged(Item item) {
        // TODO Auto-generated method stub

    }

    public void commandAction(Command c, Item item) {
        // TODO Auto-generated method stub
        if(c==save){


            if(username.getString().equals("admin") && (password.getString().equals("1234")))
            {
                adminPage admin = new adminPage(midlet,display);
                display.setCurrent(admin);

            }else if(username.getString().equals("")){  

                idBlank();

            }
            else if(password.getString().equals("")){

                pwBlank();
            }
            else 
            {

                wrongIDPW();

            }
        }else if(c==exit){
            midlet.exitMIDlet();
        }

    }

    private void pwBlank() {
        // TODO Auto-generated method stub

        Alert pwBlank = new Alert("Password cannot be blank");
        display.setCurrent(pwBlank);

    }

    private void idBlank() {
        // TODO Auto-generated method stub
        Alert idBlank = new Alert("Username cannot be blank");
        display.setCurrent(idBlank);

    }

    private void wrongIDPW() {
        // TODO Auto-generated method stub

        Alert wrong = new Alert("Username or Password is not match");
        display.setCurrent(wrong);
    }   


    }

this is the code for the login gui (i try using if else to login 1st),, and if its true,, it will directly go to adminPage but when i click Login ,, it goes to adminPage but it display nothing,,

here is the adminPage code

/**
 * 
 */
package PSM;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
 * @author Kuro
 *
 */
public class adminPage extends Form implements CommandListener {

    private Display display;
    private Login midlet;
    private Command exit;
    private List menu;

    public adminPage(Login midlet,Display display) {
        super("Admin Page");
        this.display = display;
        this.midlet = midlet;

        exit = new Command("Exit",Command.EXIT,0);
        addCommand(exit);
        menu = new List("Menu",List.IMPLICIT);
        menu.append("Add Leave",null);
        menu.setCommandListener(this);
        display.setCurrent(menu);

        // TODO Auto-generated constructor stub
    }

    public void commandAction(Command arg0, Displayable arg1) {
        // TODO Auto-generated method stub

    }

}

and this is the midlet code..

package PSM;

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

public class Login
    extends MIDlet {
    Display display;
    private LoginGUI login;

    public Login() {
        display = Display.getDisplay(this);
    }

    public void startApp() {
        login = new LoginGUI(this, display);
        display.setCurrent(login);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void exitMIDlet() {
        destroyApp(false);
        notifyDestroyed();
    }
};

please help me.. :(
it didnt show any list that i described in adminPage...

Be a part of the DaniWeb community

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