⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginmidlet.java

📁 这是j2me的例子,可供初学者学习,里面有源代码,是我写的
💻 JAVA
字号:
/*
 * LoginMidlet.java
 *
 * Created on 2007年3月28日, 下午4:15
 */

package com.tan.ui.form;

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

/**
 *
 * @author  USER
 * @version
 */
public class LoginMidlet extends MIDlet implements CommandListener{
    private Display display;
    private TextField userName;
    private TextField password;
    private Form form;
    private Command cancel;
    private Command login;
    
    public LoginMidlet()
    {
        userName = new TextField("LoginID","",10,TextField.ANY);
        password = new TextField("Password","",Command.OK,TextField.PASSWORD);
        form = new Form("Sign in");
        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) {
    }
    
    public void commandAction(Command command, Displayable displayable) {
        String label = command.getLabel();
        if(label.equals("Cancel"))
            destroyApp(true);
        else
            validateUser(userName.getString(),password.getString());
    }

    private void validateUser(String name, String password) {
        if(name.equals("wlt") && password.equals("wlt"))
            menu();
        else
            tryAgain();
    }

    private void menu() {
        List services = new List("Choose one",Choice.EXCLUSIVE);
        services.append("Check Mail",null);
        services.append("Compose",null);
        services.append("Addresses",null);
        services.append("Options",null);
        services.append("Sign Out",null);
        display.setCurrent(services);
    }

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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -