📄 regview.java
字号:
package com.tianxia.qipai.view.universal;
import java.io.IOException;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.Spacer;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Ticker;
import com.tianxia.qipai.control.universal.*;
import com.tianxia.qipai.event.*;
import com.tianxia.qipai.model.universal.RegModel;
import com.tianxia.qipai.model.util.CommStructNode;
import com.tianxia.qipai.model.util.GameEventDeal;
public class RegView implements ItemCommandListener, CommandListener,ItemStateListener,GameEventDeal{ //用来绘制注册登陆界面
private BeginControl begincontrol; //开始模块控制块
private MainGameEvent maingameevent; //事件内容
private RegModel regmodel; //界面对应的逻辑处理模块
private boolean ifsave = true; //是否保存cookies资料标志
private CommStructNode commstructnode = null; //通信结点
private TextField userid ; //用户id号
private TextField password ; //用户登录密码
private TextField supassword ; //确认密码
private TextField nickname ; //昵称
private TextField phonenum; //手机号码
private ChoiceGroup usertype; //用户类型
private ChoiceGroup sex; //性别
private int formflag; //表示当前显示的界面
private TextField age; //年龄
private ChoiceGroup picture; //头像
private ChoiceGroup cookflag; //是否保存登录cookies选择框;
private ChoiceGroup regflag; //是否是新用户注册
private Form viewform; //各种显示界面;
private List gamelist; //列表界面;
private List loginsuccview; //登陆成功界面;
private Alert alert; //各种告警框
private Display display; //屏幕
private boolean callbyself; //当前屏幕是否处在本显示界面
private Form connectfailform;
private final static Command CMD_EXIT = new Command("退出", Command.EXIT, 1);
private final static Command CMD_BACK = new Command("返回", Command.BACK, 1);
//登录界面按纽
private final static Command CMD_LOGIN = new Command("登录", Command.ITEM, 1);
//注册界面按纽
private final static Command CMD_REG = new Command("注册", Command.ITEM, 1);
//登录成功界面按纽
private final static Command CMD_AFFIM = new Command("确认", Command.ITEM, 1);
public RegView(BeginControl begincontrol) {
this.begincontrol = begincontrol;
callbyself = true;
maingameevent = begincontrol.getMainGameEvent(); //在通用开始控制器模块中获取当前事件值
display = begincontrol.getDisplay(); //获取屏幕对象
viewform = null;
gamelist = null;
loginsuccview = null;
commstructnode = maingameevent.getCommNode(); //获取事件值中通信结构的对象的值
alert = new Alert("Alert");
alert.setType(AlertType.INFO);
alert.setTimeout(Alert.FOREVER);
viewform = new Form("用户登录");
LoginFormInit(); //用户登录界面初始化
display.setCurrent(viewform);
regmodel = RegModel.getInstance();
regmodel.init(this);
}
// 用户登录界面初始化
public void LoginFormInit(){
commandClear();
formflag = BeginViewValue.loginview;
viewform.deleteAll();
viewform.setTicker(null);
viewform.setTitle("用户登录");
userid = new TextField("用户号码",commstructnode.getUserId(), 12, TextField.NUMERIC);
viewform.append(userid);
password = new TextField("用户密码", commstructnode.getPassWord(),12, TextField.PASSWORD);
viewform.append(password);
String[] CookStrings = { "保存登录资料"};
cookflag = new ChoiceGroup("", Choice.MULTIPLE,CookStrings, null);
cookflag.setSelectedIndex(0,true);
viewform.append(cookflag);
StringItem stringitem = new StringItem(null,"------------------------");
viewform.append(stringitem);
String [] regStrings = {"新用户注册"};
regflag = new ChoiceGroup("", Choice.MULTIPLE,regStrings, null);
viewform.append(regflag);
viewform.setItemStateListener(this);
viewform.addCommand(CMD_LOGIN);
viewform.addCommand(CMD_EXIT);
viewform.setCommandListener(this);
}
// 用户正在登录界面界面
public void LoginningFormInit(){
commandClear();
formflag = BeginViewValue.loginingview;
viewform.deleteAll();
viewform.setTitle("正在登录");
String temp = "正在登录,请稍等!";
viewform.setTicker(new Ticker(temp));
viewform.append(new Spacer(2,10));
}
//用户登录成功界面
public void LoginSuccFormInit(){
if(loginsuccview == null){
String[] stringArray = {"进入游戏","修改资料","游戏帮助"};
Image[] imageArray = null;
loginsuccview =new List("游戏列表", Choice.IMPLICIT, stringArray, imageArray);
loginsuccview.addCommand(CMD_EXIT);
loginsuccview.setCommandListener(this);
}
}
// 用户登录失败显示界面
private void LoginFailInit(){
password.setString(null);
alert.setTitle("登录失败");
alert.setString("用户名和密码不符合,请确认后再试!");
display.setCurrent(alert);
}
//用户注册界面初始化
public void RegFormInit(){
commandClear();
formflag = BeginViewValue.regview;
viewform.deleteAll();
viewform.setTitle("新用户注册");
nickname = new TextField("用户昵称", null, 12, TextField.ANY);
viewform.append(nickname);
password = new TextField("用户密码", null,12, TextField.PASSWORD);
viewform.append(password);
supassword = new TextField("密码确认", null,12, TextField.PASSWORD);
viewform.append(supassword);
StringItem stringitem = new StringItem(null,"-------以下选填--------");
viewform.append(stringitem);
String [] typeStrings = {"普通用户","超级用户"};
usertype = new ChoiceGroup("用户类型 ", Choice.POPUP,typeStrings, null);
viewform.append(usertype);
phonenum = new TextField("手机号码", null,12, TextField.NUMERIC);
viewform.append(phonenum);
age = new TextField("年龄", null,12, TextField.NUMERIC);
viewform.append(age);
String [] sexStrings = {"男","女"};
sex = new ChoiceGroup("性别 ", Choice.POPUP,sexStrings, null);
viewform.append(sex);
String [] picStrings = {"00","01"};
picture = new ChoiceGroup("头像 ", Choice.POPUP,picStrings, null);
viewform.append(picture);
viewform.setItemStateListener(this);
viewform.addCommand(CMD_REG);
viewform.addCommand(CMD_BACK);
viewform.setCommandListener(this);
}
// 正在提交注册资料
public void RegingFormInit(){
commandClear();
formflag = BeginViewValue.regingview;
viewform.deleteAll();
viewform.setTitle("提交注册资料");
String temp = "正在提交注册资料,请稍等!";
viewform.setTicker(new Ticker(temp));
viewform.append(new Spacer(2,10));
}
//用户注册成功界面
public void RegSuccFormInit(){
commandClear();
formflag = BeginViewValue.regsuccview;
viewform.deleteAll();
viewform.setTicker(null);
viewform.setTitle("注册成功");
StringItem stringitem = new StringItem("","------------以下是你的注册资料------------");
viewform.append(stringitem);
stringitem = new StringItem("用户号码: ",commstructnode.getUserId());
viewform.append(stringitem);
stringitem = new StringItem("用户昵称: ",commstructnode.getNickName());
viewform.append(stringitem);
stringitem = new StringItem("手机号码: ",commstructnode.getPhonenum());
viewform.append(stringitem);
if(commstructnode.getSex() == 1){
stringitem = new StringItem("用户性别: ","男");
}
else{
stringitem = new StringItem("用户性别: ","女");
}
viewform.append(stringitem);
stringitem = new StringItem("头像",commstructnode.getPicture());
viewform.append(stringitem);
stringitem = new StringItem("游戏币: ",commstructnode.getGameMoney());
viewform.append(stringitem);
viewform.addCommand(CMD_EXIT);
viewform.addCommand(CMD_AFFIM);
viewform.setCommandListener(this);
}
//用户被强行注销显示界面
private void LogoutInit(String reasonstr){
commandClear();
formflag = BeginViewValue.belogoutview;
viewform.deleteAll();
viewform.setTicker(null);
viewform.setTitle("已经被注销");
StringItem stringitem = new StringItem("","------------以下是注销的原因------------");
viewform.append(stringitem);
stringitem = new StringItem("",reasonstr);
viewform.append(stringitem);
viewform.addCommand(CMD_AFFIM);
viewform.setCommandListener(this);
}
//用户资料修改界面初试化
private void ModifyDeal(){
commandClear();
viewform.deleteAll();
viewform.setTicker(null);
RegFormInit();
formflag = BeginViewValue.modifyview;
viewform.setTitle("资料修改");
nickname.setString(commstructnode.getNickName());
password.setString(commstructnode.getPassWord());
viewform.removeCommand(CMD_REG);
viewform.addCommand(CMD_AFFIM);
}
// 正在提交修改资料
private void ModifyingDeal(){
commandClear();
formflag = BeginViewValue.regingview;
viewform.deleteAll();
viewform.setTitle("提交修改资料");
String temp = "正在提交新的用户资料,请稍等!";
viewform.setTicker(new Ticker(temp));
viewform.append(new Spacer(2,10));
}
// 用户资料修改成功显示界面
private void ModifySuccInit(){
commandClear();
formflag = BeginViewValue.modifysuccview;
viewform.deleteAll();
viewform.setTitle("提交完成");
String temp = "您的资料已成功修改!";
viewform.setTicker(new Ticker(temp));
viewform.append(new Spacer(2,10));
}
// 用户资料修改失败显示界面
private void ModifyFailInit(){
commandClear();
formflag = BeginViewValue.regingview;
viewform.deleteAll();
viewform.setTitle("提交失败");
String temp = "资料提交失败,请确认您的输入后,稍后再试!";
viewform.setTicker(new Ticker(temp));
viewform.append(new Spacer(2,10));
}
private void GameListInit(){
if(gamelist ==null){
String[] stringArray = {
"五子棋",
"麻将",
"斗地主",
"双扣"
};
Image gobangimage = null;
try {
gobangimage = Image.createImage("/png/icon.png");
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
Image[] imageArray = {gobangimage,null,null,null};
gobangimage = null;
begincontrol.rt.gc();
gamelist =new List("游戏列表", Choice.IMPLICIT, stringArray, imageArray);
gamelist.addCommand(CMD_BACK);
gamelist.setCommandListener(this);
}
}
//系统忙错误提示界面(处理所有未定义的错误)
public void SystemErrDeal(){
alert.setTitle("系统忙");
alert.setString("对不起,系统正忙,请稍后再试!");
display.setCurrent(alert);
begincontrol.handleEvent(MainGameEvent.MAINGAMEEXIT,maingameevent);
}
// 无法连接服务器提示界面
private void DisConPromptInit(){
commandClear();
formflag = BeginViewValue.disconnectview;
viewform.deleteAll();
viewform.setTitle("与服务器断开");
String temp = "无法重新连接服务器,请稍后重新登陆!";
viewform.append(temp);
viewform.addCommand(CMD_AFFIM);
viewform.setCommandListener(this);
}
//清除viewform上所有命令
private void commandClear(){
viewform.removeCommand(CMD_LOGIN);
viewform.removeCommand(CMD_REG);
viewform.removeCommand(CMD_EXIT);
viewform.removeCommand(CMD_BACK);
viewform.removeCommand(CMD_AFFIM);
}
public void commandAction(Command arg0, Item arg1) {
// TODO 自动生成方法存根
}
//响应用户的命令操作
public void commandAction(Command command, Displayable disable) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -