J2ME---登录框
来源:互联网 发布:windows域的搭建 编辑:程序博客网 时间:2024/05/18 00:48
程序源代码:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ScreenDemo extends MIDlet implements CommandListener
{
private Display display;//设备的显示器
private TextField userName;
private TextField password;
private Form form;//表单
private Command cancel;//取消命令
private Command login;//登陆命令
public ScreenDemo()
{
userName = new TextField("用户名","",10,TextField.ANY);
password = new TextField("密码","",10,TextField.PASSWORD);
form = new Form("用户登陆");
cancel = new Command("取消",Command.CANCEL,1);
login = new Command("登陆",Command.OK,2);
}
protected void startApp()
{
display = Display.getDisplay(this);
Ticker ticker = new Ticker("请输入用户名和密码");
form.setTicker(ticker);
form.append(userName);
form.append(password);
form.addCommand(cancel);
form.addCommand(login);
form.setCommandListener(this);
display.setCurrent(form);//显示表单
}
protected void pauseApp(){}//重载抽象类MIDlet的抽象方法pauseApp()
protected void destroyApp(boolean u)
{
notifyDestroyed();
}
protected void validateUser(String name,String password)
{
if(name.equals("1")&&password.equals("1"))
{
passed();
}
else
{
tryAgain();
}
}
protected void passed()
{//登陆成功时显示登陆成功信息
//登陆成功警报
Alert pass = new Alert("登陆信息","你已经成功登陆",null,AlertType.ERROR);
pass.setTimeout(Alert.FOREVER);
display.setCurrent(pass,form);
}
protected void tryAgain()
{//登陆错误时,显示错误信息
//登陆错误警报
Alert errors = new Alert("登陆错误","请重新输入用户名和密码",null,AlertType.ERROR);
errors.setTimeout(Alert.FOREVER);
userName.setString("");
password.setString("");
display.setCurrent(errors,form);
}
public void commandAction(Command c,Displayable d)
{
if(c == cancel)
{
destroyApp(false);
notifyDestroyed();
}
else if(c == login)
{
validateUser(userName.getString(),password.getString());
}
}
程序运行结果:
}
- J2ME---登录框
- J2ME road——J2ME实现TextField登录界面
- J2ME/J2EE实现用户登录交互
- J2ME/J2EE实现用户登录交互
- j2me实现登陆框
- j2me框架教程(4)--登录页面的实现
- J2ME版中国移动飞信通信协议 (4) 登录导航服务器
- j2me
- j2me
- J2ME
- J2ME
- j2me
- J2ME
- j2me
- j2me
- j2me
- J2ME
- j2me
- C# Visual Studio 2005中将一个TextBox中的内容通过FileStream写到文件中
- 更换XP序列号的代码!
- C# Visual Studio 2005中用FileStream将一个文件中的内容读取出来并赋给一个变量
- spread 7.0 注册机
- UART(通用异步收发器)简介
- J2ME---登录框
- vc读写Excel文件的方法
- 为什么开blog?
- XP SP2下Apache(2.2.4)+php(5.2.3)安装过程!
- [Reentrant Kernels]
- 返回数据表中同一列中相同值的个数
- C++编写的ATM自动取款机模拟程序
- ILMerge 工具 合并多个程序集
- 从VC++到GCC移植:谈两者语法差异