⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addfriendform.java

📁 J2ME的源码!我以前学习J2ME的源码哈!非常适合初学者
💻 JAVA
字号:
/**
 * @(#)AddFriendForm.java	
 * Copyright (c) 2004-2005 wuhua of workroom Inc. All Rights Reserved.
 * @version 	1.0, 10/05/2004
 * @author 	饶荣庆
 * @author 	
 */
package org.wuhua.photobook;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

import org.wuhua.fuck.core.SQLException;
import org.wuhua.photobook.model.Friend;
import org.wuhua.photobook.service.Service;

/**
 *新增功能的类
 */
public class  AddFriendForm extends Form implements CommandListener 
{
	private Display display = null;
	private Menu menu = null;
	public static Alert addAlert = null;	//定义为静态是为了利于修改属性
	public static Alert modifyAlert = null; 
	public static Alert infoAlert = new Alert(null, null, null, AlertType.INFO); 	 //动态的改变语言 
	public   TextField addressTextField= null;
	public   TextField nameTextField= null;
	public   TextField phoneTextField= null;
	public   TextField eMailTextField= null;
	public Command okCommand = null;			//定义确定软键
	public Command backCommand = null;			//定义离开软键
	public Command confirmCommand = null;			//定义确定软键
	public Command cancelCommand = 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.addressTextField = new TextField("输入地址", null, 100, TextField.ANY);
		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(nameTextField);
		this.append(phoneTextField);
		this.append(eMailTextField);
		this.append(addressTextField);
	    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, Menu menu)	//用来显示界面
	{
		this.display = display;
	    this.menu = menu;
		this.display.setCurrent(this);
	}

	public void commandAction(Command c,Displayable s)
	{ 
		if(c == okCommand){
			addFriend();
		}else if(c == this.backCommand){
			 this.display.setCurrent(menu);
		}
	}

	private void addFriend() {
		 Friend friend = new Friend();
		 friend.setEMail(this.eMailTextField.getString());
		 friend.setName(this.nameTextField.getString());
		 friend.setPhone(this.phoneTextField.getString());
		 friend.setAddress(this.addressTextField.getString());
		 try {
			Service.getInstance().addFriend(friend);
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		
	}  
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -