📄 setform.java
字号:
/*
* SetForm.java
*
* Created on 2007年3月11日, 下午4:10
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package net.bccn.account.ui;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.TextField;
import net.bccn.account.model.MySet;
import net.bccn.account.util.Record;
import net.bccn.account.util.Util;
/**
*
* @author hadeslee
*/
public class SetForm extends Form implements CommandListener,ItemStateListener{
private static SetForm sf;
private Command back,ok;
private MySet my;
private TextField origin,pwd1,pwd2;
private ChoiceGroup select;
/** Creates a new instance of SetForm */
private SetForm() {
super("设置");
initWindow();
}
private void initWindow(){
Record[] rds=Util.getAllRecords(new MySet());
if(rds!=null&&rds.length>0){
my=(MySet)rds[0];
}
back=new Command("返回",Command.BACK,0);
ok=new Command("确定",Command.OK,1);
this.addCommand(back);
this.addCommand(ok);
this.setCommandListener(this);
this.setItemStateListener(this);
origin=new TextField("请输入密码",null,8,TextField.PASSWORD);
pwd1=new TextField("新密码",null,8,TextField.PASSWORD);
pwd2=new TextField("确认密码",null,8,TextField.PASSWORD);
select=new ChoiceGroup("请选择",Choice.EXCLUSIVE,
new String[]{"更改密码","取消密码","起用密码"},null);
this.append(select);
if(my!=null){
this.append(origin);
}
this.append(pwd1);
this.append(pwd2);
}
public static SetForm getInstance(){
if(sf==null){
sf=new SetForm();
}
return sf;
}
public void commandAction(Command command, Displayable displayable) {
if(command==ok){
int index=select.getSelectedIndex();
if(index==0){
if(my==null){
String p1=pwd1.getString();
String p2=pwd2.getString();
if(p1!=null&&p2!=null&&p1.equals(p2)){
my=new MySet();
my.setPwd(p1);
my.setIsPwd(true);
boolean b=Util.saveRecord(my);
if(b){
Util.showINFO(AlertType.INFO,"密码修改成功!!",MainForm.getInstance());
pwd1.setString(null);
pwd2.setString(null);
origin.setString(null);
}else{
Util.showINFO(AlertType.ERROR,"密码修改失败!!");
}
}else{
Util.showINFO(AlertType.ERROR,"两次密码输入不一致!!");
Util.moveTo(pwd1);
}
}else{
String or=origin.getString();
if(or==null||!or.equals(my.getPwd())){
Util.showINFO(AlertType.ERROR,"原始密码输入有误!");
origin.setString(null);
Util.moveTo(origin);
}else{
String p1=pwd1.getString();
String p2=pwd2.getString();
if(p1!=null&&p2!=null&&p1.equals(p2)){
my.setPwd(p1);
my.setIsPwd(true);
boolean b=Util.updateRecord(my);
if(b){
Util.showINFO(AlertType.INFO,"密码修改成功!!",MainForm.getInstance());
pwd1.setString(null);
pwd2.setString(null);
}else{
Util.showINFO(AlertType.ERROR,"密码修改失败!!");
}
}else{
Util.showINFO(AlertType.ERROR,"两次密码输入不一致!!");
Util.moveTo(pwd1);
}
}
}
}else if(index==1){
if(my==null||!my.getIsPwd()){
Util.showINFO(AlertType.INFO,"取消密码保护成功!!",MainForm.getInstance());
}else{
String p=origin.getString();
if(p==null||!p.equals(my.getPwd())){
Util.showINFO(AlertType.ERROR,"密码输入错误!!");
origin.setString(null);
Util.moveTo(origin);
}else{
my.setIsPwd(false);
boolean b=Util.updateRecord(my);
if(b){
Util.showINFO(AlertType.INFO,"取消密码保护成功!!",MainForm.getInstance());
origin.setString(null);
}else{
Util.showINFO(AlertType.ERROR,"取消密码保护失败!!");
}
}
}
}else if(index==2){
if(my==null){
String p1=pwd1.getString();
String p2=pwd2.getString();
if(p1!=null&&p2!=null&&p1.equals(p2)){
my=new MySet();
my.setPwd(p1);
my.setIsPwd(true);
boolean b=Util.saveRecord(my);
if(b){
Util.showINFO(AlertType.INFO,"启用密码保护成功!",MainForm.getInstance());
pwd1.setString(null);
pwd2.setString(null);
}else{
Util.showINFO(AlertType.ERROR,"启用密码保护失败!!");
}
}else{
Util.showINFO(AlertType.ERROR,"两次密码输入不一致!!");
pwd1.setString(null);
pwd2.setString(null);
Util.moveTo(pwd1);
}
}else{
my.setIsPwd(true);
boolean b=Util.updateRecord(my);
if(b){
Util.showINFO(AlertType.CONFIRMATION,"启用密码保护成功!!",MainForm.getInstance());
pwd1.setString(null);
pwd2.setString(null);
}else{
Util.showINFO(AlertType.CONFIRMATION,"启用密码保护失败!!");
pwd1.setString(null);
pwd2.setString(null);
}
}
}
}else if(command==back){
Util.changeTo(Util.MAIN_FORM);
}
}
public void itemStateChanged(Item item){
if(item==select){
int index=select.getSelectedIndex();
if(index==0){
if(my==null){
this.deleteAll();
this.append(select);
this.append(pwd1);
this.append(pwd2);
}else{
this.deleteAll();
this.append(select);
this.append(origin);
this.append(pwd1);
this.append(pwd2);
}
}else if(index==1){
if(my!=null){
this.deleteAll();
this.append(select);
this.append(origin);
}else{
this.deleteAll();
this.append(select);
}
}else if(index==2){
if(my==null){
this.deleteAll();
this.append(select);
this.append(pwd1);
this.append(pwd2);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -