📄 modifyfriend.java
字号:
/**
* @(#)ModifyFriend.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 ModifyFriend extends Form implements CommandListener
{
private Display display = null;
private PhoneBookMenu phoneBookMenu = null;
public static Alert infoAlert = new Alert(null, null, null, AlertType.INFO); //动态的改变语言
public Alert alert = null;
public StringItem idItem = null;
public TextField nameTextField= null;
public TextField phoneTextField= null;
public TextField eMailTextField= null;
public Command okCommand = null; //定义确定软键
public Command backCommand = null; //定义离开软键
private boolean isModify = true; //确定可以修改
private int _id;
public ModifyFriend(String s)
{
super(s);
this.alert = new Alert("提示", "修改成功", null, AlertType.INFO); //初始化信息
this.alert.setTimeout(1000);
this.infoAlert.setTimeout(1000);
this.okCommand = new Command("确定", Command.OK, 2);
this.backCommand = new Command("返回", Command.BACK, 2);
this.idItem = new StringItem("ID是", null);
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(idItem);
this.append(nameTextField);
this.append(phoneTextField);
this.append(eMailTextField);
this.addCommand(backCommand);
this.addCommand(okCommand);
this.setCommandListener(this);
}
public void showForm(Display display, PhoneBookMenu phoneBookMenu, int id, String name, String phone, String eMail) //用来显示界面
{
this.idItem.setText(id + "");
this.nameTextField.setString(name);
this.phoneTextField.setString(phone);
this.eMailTextField.setString(eMail);
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) //修改
{
PhoneBook pb = new PhoneBook();
try
{
_id = Integer.parseInt(idItem.getText());
}
catch(NumberFormatException e)
{
this.display.setCurrent(infoAlert);
isModify = false;
}
String _name = nameTextField.getString();
String _phone = phoneTextField.getString();
String _eMail = eMailTextField.getString();
if (_name.compareTo("") == 0)
{
this.display.setCurrent(infoAlert);
isModify = false;
}
if (_phone.compareTo("") == 0)
{
this.display.setCurrent(infoAlert);
isModify = false;
}
if (isModify == true) //确定修改
{
pb.modifyFriend(_id, _name, _phone, _eMail); //调用修改方法
this.display.setCurrent(alert, phoneBookMenu);
pb.closeRS();
}
isModify =true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -