pwdform.java

来自「一个j2me很简单的用户名密码注册的登陆框源代码」· Java 代码 · 共 87 行

JAVA
87
字号
import java.io.IOException;
import java.util.Enumeration;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.TextField;

//修改密码界面
public class PWDForm extends Form implements CommandListener
{
	private Command cancel;
	private Command ok;
	
	private TextField pwd_old;
	private TextField pwd_new;
	private TextField pwd_con;
	
	private User user;
	
	public PWDForm(String title, User user)
	{
		super(title);
		
		this.user = user;
		
		cancel = new Command("取消", Command.CANCEL, 1);
		ok = new Command("确定", Command.OK, 1);
		
		pwd_old = new TextField("旧密码:", null, 20, TextField.PASSWORD);
		pwd_new = new TextField("新密码:", null, 20, TextField.PASSWORD);
		pwd_con = new TextField("确认新密码:", null, 20, TextField.PASSWORD);
		
		this.append(pwd_old);
		this.append(pwd_new);
		this.append(pwd_con);
		this.addCommand(cancel);
		this.addCommand(ok);
		this.setCommandListener(this);
	}

	public void commandAction(Command c, Displayable d)
	{
		if (c.equals(cancel))
		{
			MyLoginMIDlet.midlet.showWelcomeList(this.user);
		}
		else if (c.equals(ok))
		{	
			String pOld = pwd_old.getString();
			String pNew = pwd_new.getString();
			String pCon = pwd_con.getString();
			
			if (!pOld.equals(user.getPWD()))
			{
				Alert al = new Alert("错误", "旧密码错误!", null, AlertType.ERROR);
				al.setTimeout(2000);
				MyLoginMIDlet.midlet.showAlert(al, this);
				return;
			}
			
			if (!pNew.equals(pCon))
			{
				Alert al = new Alert("错误", "确认新密码错误!", null, AlertType.ERROR);
				al.setTimeout(2000);
				MyLoginMIDlet.midlet.showAlert(al, this);
				return;
			}
			
			int index = MyLoginMIDlet.userList.indexOf(this.user);
			this.user.setPWD(pNew);
			MyLoginMIDlet.userList.setElementAt(this.user, index);
			
			Alert al = new Alert("密码修改", this.user.getUserName()+"密码修改成功!", null, AlertType.INFO);
			al.setTimeout(2000);
			WelcomeList list = new WelcomeList(user.getUserName()+",欢迎光临!",Choice.IMPLICIT, user);
			MyLoginMIDlet.midlet.showAlert(al, list);
		}
	}

}

⌨️ 快捷键说明

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