关于用户登陆的界面的问题

ghb9812052 2008-05-27 06:22:21
各位大侠,我设计了一个手机用户登陆的应用 上面主要的是有三个 textField 分别是:账号,密码,服务器。
在应用程序启动的时候,光标是停在第一行,完成输入后按Enter键,这个时候默认的进行的换行操作(光标没有到密码框那一行)。而我想要实现的功能是每按一次enter 键就切换到下一个对话框,直到最后一行(服务器那一行)按enter键,才开始用户登陆。请各位帮我想想这个怎么实现。我写了一段代码,但是不成功。请各位高手帮我指点一下,谢谢!!

代码如下:

public class SetAccountDraw extends FancyBaseComponent implements CommandListener, OnTimeCallBack {

private Form f;
private TextField account, password, tf;
private Command okCommand = new Command("确定", Command.OK, 1);
private Command backCommand = new Command("退出", Command.BACK, 2);

wind.mobile.MainApp midapp;

boolean lock;
long time;
private int position = 0;

public SetAccountDraw(AppFramework app, int type, String strTitle, wind.mobile.MainApp midapp) {
super(new ScreenCanvas(app, type, strTitle));
this.midapp = midapp;
this.container.addFancyListener(this);
addForm("输入账号密码");
}

private void addForm(String title) {
f = new Form(title);
account = new TextField("帐号:", Constant.UserName, 50, TextField.ANY);
password = new TextField("密码:", Constant.Password, 50, TextField.PASSWORD);
tf = new TextField("服务器:", Constant.HostPort, 50, TextField.ANY);
if (Constant.NetType == 2)
tf = new TextField("服务器:", Constant.dlHost, 50, TextField.ANY);// Constant.dlHost
else
tf = new TextField("服务器:", Constant.HostPort, 50, TextField.ANY);// Constant.HostPort

f.append(account);
f.append(password);
f.append(tf);

f.addCommand(backCommand);
f.addCommand(okCommand);

f.setCommandListener(this);
AppFramework.instance.getDisplay().setCurrent(f);
}

public void OnTime(byte[] data2) {
try {
lock = false;
if (data2 != null) {
DataInputStream reader = new DataInputStream(new ByteArrayInputStream(data2));
AdvanceReader reader2 = new AdvanceReader(reader);
int update = reader2.readCInt();
int r = reader2.readCInt();

if (r == 0) {
System.out.println(" check success!");
Constant.UserName = account.getString();
Constant.Password = password.getString();
if (Constant.NetType == 2)
Constant.dlHost = tf.getString();
else
Constant.HostPort = tf.getString();
AppFramework.instance.saveSettings();

f.setTitle("帐号验证成功");
MainMenuDraw mmd = new MainMenuDraw(AppFramework.instance, AppFramework.SC_TYPE_MAIN, "万得资讯手机版1.0(Beta)");
AppFramework.instance.pushScreen(mmd);

} else {
int len = reader2.readCInt();
String title = reader2.readString(len);
Constant.UserName = account.getString();
Constant.HostPort = tf.getString();

Alert a = new Alert("登陆失败", title, null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
AppFramework.instance.getDisplay().setCurrent(a, f);

password.setString("");
}

} else {
System.out.println(" check failed!");
if (Constant.NetType == 2)
Constant.dlHost = tf.getString();
else
Constant.HostPort = tf.getString();
// addForm("账号或密码不对");

password.setString("");

AppFramework.instance.getDisplay().setCurrent(a, f);

// addForm(title);
password.setString("");

}

} catch (Exception e) {
e.printStackTrace();
}
}

public void commandAction(Command c, Displayable s) {
if (c == okCommand && (!lock || lock && System.currentTimeMillis() - time > 5000)) {
try {
MD5 md5 = new MD5();
String phoneNumber = "";
String version = "";


phoneNumber = Phone.getDevicePhoneNumber(false);
ApplicationDescriptor descriptor = ApplicationDescriptor.currentApplicationDescriptor();
version = CommonFunc.FilterString(descriptor.getVersion(), ".");

if (Constant.NetType == 2)
Constant.dlHost = tf.getString();
else
Constant.HostPort = tf.getString();

String url = "http://" + Constant.HostPort + "/WBBWebService/DataGetor.aspx?type=00000001" + "&u=" + account.getString() + "&p=" + md5.getMD5ofStr(password.getString()) + "&ph="
+ phoneNumber + "&v=" + version;

OnTimeMission otm = new OnTimeMission(this, url);
otm.start();
time = System.currentTimeMillis();
lock = true;
} catch (Exception e) {

}

} else if (c == backCommand) {
midapp.Destroy();
}
}

// 控制键盘
public synchronized void keyPressed(int keyCode) {
switch (keyCode) {
case Platform.KEY_ENTER : {
if (position < 2) {
this.position++;
this.keyPressed(Canvas.DOWN);
} else {

}
break;
}
case Platform.KEY_UP : {

if (this.position > 0)
this.position--;
break;
}
case Platform.KEY_DOWN : {

if (this.position < 2)
this.position++;
break;
}
}
}

}
...全文
84 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ghb9812052 2008-05-28
  • 打赏
  • 举报
回复
现在我就是不知道在canvas 中怎么样来监听 按键事件?有没有例子之类的?
saltedfish_zl 2008-05-28
  • 打赏
  • 举报
回复
基本上在高级UI上是无法实现LZ的想法的。
不能用Form等来实现,只能用canvas来自己画界面并监听按键时间,置于输入只能切换到textbox上。

saltedfish
saltedfish_zl 2008-05-28
  • 打赏
  • 举报
回复
LZ实在有才,自己给Form添加keyPressed方法阿。
这是行不通的阿。
看看Form的API文档吧,是没有keypRessed方法的,只有Canvas才有;所以按键事件是不会传给你想当然添加的keyPressed方法。
我告诉LZ的是,你要的效果是不能用Form等高级UI实现的,只能自己用canvas来实现。

LZ写的代码有点让人看不明白,让人感觉你并没有对J2ME的架构理解正确,看上去并不是一个J2me的代码,倒像是把awt或swing的概念直接往j2me上套。


saltedfish
ghb9812052 2008-05-28
  • 打赏
  • 举报
回复
我上面的代码中已经添加了 KeyPressed() 的方法,但是运行的时候,这个事件并没有捕捉到。
saltedfish_zl 2008-05-28
  • 打赏
  • 举报
回复
看看canvas的keyPressed()等方法。


saltedfish
老紫竹 2008-05-27
  • 打赏
  • 举报
回复
截获键盘事件

然后内部转换为 TAB 键

参考这个 http://www.java2000.net/viewthread.jsp?tid=147

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧