📄 addfriendform.java
字号:
/**
* @(#)AddFriendForm.java
* Copyright (c) 2004-2005 wuhua of workroom Inc. All Rights Reserved.
* @version 1.0, 10/05/2004
* @author 饶荣庆
* @author
*/
package com.j2me.phonebook;
import com.j2me.main.*;
import javax.microedition.lcdui.*;
/**
*新增功能的类
*/
public class AddFriendForm extends Form implements CommandListener
{
private Display display = null;
private PhoneBookMenu phoneBookMenu = null;
public static Alert addAlert = null; //定义为静态是为了利于修改属性
public static Alert modifyAlert = null;
public static Alert infoAlert = new Alert(null, null, null, AlertType.INFO); //动态的改变语言
public static TextField idTextField= null;
public static TextField nameTextField= null;
public static TextField phoneTextField= null;
public static TextField eMailTextField= null;
public Command okCommand = null; //定义确定软键
public Command backCommand = null; //定义离开软键
public Command confirmCommand = null; //定义确定软键
public Command cancelCommand = null; //定义取消软键
private PhoneBook pb = null;
private int _id ;
private String _name;
private String _phone;
private String _eMail;
private int recordID;
private boolean isAdd = true;
public AddFriendForm(String s)
{
super(s);
this.addAlert = new Alert("提示", "添加成功", null, AlertType.INFO); //初始化信息
this.addAlert.setTimeout(1000);
this.modifyAlert = new Alert("提示", "这条记录已经存在!是否对它进行修改!", null, AlertType.INFO); //初始化信息
this.modifyAlert.setTimeout(1000);
this.infoAlert.setTimeout(1000);
this.okCommand = new Command("确定", Command.OK, 2);
this.backCommand = new Command("返回", Command.BACK, 2);
this.confirmCommand = new Command("确定", Command.OK, 2);
this.cancelCommand = new Command("取消", Command.BACK, 2);
this.idTextField = new TextField("输入ID", null, 3, TextField.NUMERIC);
this.nameTextField = new TextField("输入名", null, 30, TextField.ANY);
this.phoneTextField = new TextField("输入电话", null, 15, TextField.PHONENUMBER);
this.eMailTextField = new TextField("输入邮箱", null, 50, TextField.EMAILADDR);
this.append(idTextField);
this.append(nameTextField);
this.append(phoneTextField);
this.append(eMailTextField);
this.modifyAlert.addCommand(confirmCommand);
this.modifyAlert.addCommand(cancelCommand);
this.modifyAlert.setCommandListener(this);
this.addCommand(backCommand);
this.addCommand(okCommand);
this.setCommandListener(this);
}
public void showForm(Display display, PhoneBookMenu phoneBookMenu) //用来显示界面
{
this.display = display;
this.phoneBookMenu = phoneBookMenu;
this.display.setCurrent(this);
}
public void commandAction(Command c,Displayable s)
{
if(c == backCommand)
{
this.display.setCurrent(phoneBookMenu);
}
if( c == okCommand)
{
this.pb = new PhoneBook();
try
{
_id = Integer.parseInt(idTextField.getString());
}
catch(NumberFormatException e)
{
this.display.setCurrent(infoAlert);
isAdd = false;
}
_name = nameTextField.getString();
_phone = phoneTextField.getString();
_eMail = eMailTextField.getString();
int recordID = pb.getRecordIDByID(_id);
if (_name.compareTo("") == 0)
{
this.display.setCurrent(infoAlert);
isAdd = false;
}
if (_phone.compareTo("") == 0)
{
this.display.setCurrent(infoAlert);
isAdd = false;
}
if (isAdd == true)
{
//如果记录中没有对应的记录则增加一条
if (recordID == -1)
{
pb.addFriend(_id, _name, _phone, _eMail);//addAlert.setString("操作成功");
this.display.setCurrent(addAlert);
}
//如果已存在一条对应的记录,则修改对应的记录
else
{
this.display.setCurrent(modifyAlert);
}
}
isAdd = true; //重新设置我真,保证下次运行正常
pb.closeRS();
}
if (c == confirmCommand)
{
pb.modifyFriend(_id, _name, _phone, _eMail);
this.display.setCurrent(this);
}
if (c == cancelCommand)
{
this.display.setCurrent(this);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -