personalinfoform.java

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

JAVA
68
字号
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 PersonalInfoForm extends Form implements CommandListener
{
	private Command cancel;
	private Command ok;
	
	private TextField realName;
	private TextField age;
	
	private User user;
	
	public PersonalInfoForm(String title, User user)
	{
		super(title);
		
		this.user = user;
		
		cancel = new Command("取消", Command.CANCEL, 1);
		ok = new Command("确定", Command.OK, 1);
		
		realName = new TextField("真实姓名:", user.getRealName(), 20, TextField.ANY);
		age = new TextField("年龄:", Integer.toString(user.getAge()), 20, TextField.NUMERIC);
		
		this.append(realName);
		this.append(age);
		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 rn = realName.getString();
			int age = Integer.parseInt(this.age.getString());
			
			int index = MyLoginMIDlet.userList.indexOf(this.user);
			this.user.setRealName(rn);
			this.user.setAge(age);
			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 + -
显示快捷键?