合肥学院
计算机科学与技术系
课程设计报告
2013~20##学年第二学期
20 年 月
目 录
一、设计题目·················································1
二、设计要求·················································1
三、总体设计·················································1
3.1系统功能框架········································· 1
3.2系统功能说明··········································3
四、详细设计···················································3
1.数据结构设计············································3
2.系统模块设计············································10
五、运行结果·················································13
一. 设计题目
随着社会的进步与发展,通讯越来越密切。希望能通过对java课程设计的学习和掌握来编写一个通讯录管理系统。
二.设计要求
(1)只能使用Java语言,采用面向对象方法进行设计,要求源程序要有适当的注释,使程序容易阅读。
(2)程序必须与数据库进行通信。
(3)系统必须是图形用户界面的形式并连接数据库
三. 总体设计
3.1系统总体功能框架图
3.2 系统功能说明
(1)具有新用户注册功能。
(2)具有注册用户登录功能。
(3)具有数据的录入功能。
(4)具有数据查询功能,可以实现查询全部信息和按条件执行查询。
(5)具有按条件删除数据功能。
(6)具有统计功能
4. 详细设计
4.1数据结构设计(java程序设计)
//登录系统
package com.ibm.etp.addressbook.action;
import java.util.HashMap;
import java.util.List;
import com.ibm.etp.addressbook.pojo.User;
import com.ibm.etp.addressbook.service.LoginService;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
private static final long serialVersionUID = 1L;
public String username;
public String password;
private String message;
@Override
public String execute() throws Exception {
HashMap<Object, Object> result = new HashMap<Object, Object>();
List<User> list = null;
System.out.println(username);
if(username == null || username.trim().length() == 0) {
result.put("success", false);
result.put("msg", "login.username.empty");
} else if(password == null || password.trim().length() == 0) {
result.put("success", false);
result.put("msg", "login.password.empty");
} else {
LoginService ls = new LoginService();
list = ls.checkLogin(username);
}
if(list == null) {
result.put("success", false);
result.put("msg", "error.user.not.exist");
} else if(list.get(0).getPassword().equals(password)) {
result.put("success", true);
result.put("msg", "login.success");
} else {
result.put("success", false);
result.put("msg", "error.password.wrong");
}
if((Boolean) result.get("success")) {
message = (String) result.get("msg");
return "success";
} else {
message = (String) result.get("msg");
return "error";
}
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
}
//增加记录
package com.ibm.etp.addressbook.action;
import java.util.HashMap;
import java.util.List;
import com.ibm.etp.addressbook.pojo.User;
import com.ibm.etp.addressbook.service.LoginService;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
private static final long serialVersionUID = 1L;
public String username;
public String password;
private String message;
public String execute() throws Exception {
HashMap<Object, Object> result = new HashMap<Object, Object>();
List<User> list = null;
System.out.println(username);
if(username == null || username.trim().length() == 0) {
result.put("success", false);
result.put("msg", "login.username.empty");
} else if(password == null || password.trim().length() == 0) {
result.put("success", false);
result.put("msg", "login.password.empty");
} else {
LoginService ls = new LoginService();
list = ls.checkLogin(username);
}
if(list == null) {
result.put("success", false);
result.put("msg", "error.user.not.exist");
} else if(list.get(0).getPassword().equals(password)) {
result.put("success", true);
result.put("msg", "login.success");
} else {
result.put("success", false);
result.put("msg", "error.password.wrong");
}
if((Boolean) result.get("success")) {
message = (String) result.get("msg");
return "success";
} else {
message = (String) result.get("msg");
return "error";
}
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
}
//删除记录
package com.ibm.etp.addressbook.action;
import java.util.ArrayList;
import com.ibm.etp.addressbook.pojo.Record;
import com.ibm.etp.addressbook.service.DeleService;
import com.opensymphony.xwork2.ActionSupport;
public class DeleAction extends ActionSupport {
private int id[];
public String message;
private boolean success=true;
public boolean isSuccess() {
return success;
}
private ArrayList<Record> list= new ArrayList<Record>();
public ArrayList<Record> getList() {
return list;
}
public int getId(int i){
return id[i];
}
public int[] getId() {
return id;
}
public void setId(int[] id) {
this.id = id;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String execute() throws Exception {
DeleService ds=new DeleService();
list=ds.removeRecord(this);
try {
success=true;
return SUCCESS;
}catch (Exception e) {
success=false;
return ERROR;
}
}
}
//修改记录
package com.ibm.etp.addressbook.action;
import com.ibm.etp.addressbook.service.UpdateService;
import com.opensymphony.xwork2.ActionSupport;
public class UpdateAction extends ActionSupport {
private int id;
private String name;
private String phone;
private String email;
private String birthday;
private String sex;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String execute() throws Exception {
UpdateService us=new UpdateService();
if(us.setRecord(this)!=null)
return SUCCESS;
else{
return ERROR;
}
}
}
//查找记录行
package com.ibm.etp.addressbook.action;
import java.sql.SQLException;
import java.util.List;
import com.ibm.etp.addressbook.pojo.Record;
import com.ibm.etp.addressbook.service.FindService;
import com.opensymphony.xwork2.ActionSupport;
public class FindAction extends ActionSupport {
private String field;
private String input;
private int size;
private String sort;
private List<Record> list ;
private boolean success=true;
public boolean isSuccess() {
return success;
}
public List<Record> getList() {
return list;
}
public void setList(List<Record> list) {
this.list = list;
}
public String getField() {
return field;
}
public void setField(String field) {
this.field = field;
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getSort() {
return sort;
}
public void setSort(String sort) {
this.sort = sort;
}
public String execute() throws Exception {
FindAction fb = new FindAction();
fb.setField(field);
fb.setInput(input);
fb.setSize(size);
fb.setSort(sort);
FindService fs = new FindService();
try {
list = fs.find(fb);
success=true;
return SUCCESS;
} catch (SQLException e) {
e.printStackTrace();
success=false;
return ERROR;
4.2 系统模块设计
图1-1登陆功能展示图
LoginAction类,封装的信息由密码和账户名,以及登录失败时抛出的异常方法。String execute()函数继承了Exception类,如果登录密码不匹配,则会抛出异常,提示Error登录失败。在登录模块中有管理员用户和普通用户,管理员可以对系统中的信息添加,修改,删除等功能,普通用户只进行查找操作。
2、添加功能界面
图2-1添加功能展示图
LoginAction类继承ActionSuporrt类,封装有name,sex,birthday,email,tel属性,封装有成员函数set_name(),set_sex(),set_birthday(),set_email(),set_tel()用来添加各个属性值,提示操作失败信息用String execute()函数抛出异常。
3、删除功能界面
图3-1删除功能展示图
DeleAction类继承ActionSuporrt类,get_name()方法用于得到所要删除的信息的主码。封装的数据成员包括name,封装有isSuccess()函数,用于判断删除成功与否。删除模块中,用户可以根据某一关键字或多个关键字进行删除,删除信息后会自动提示。
4、查询功能界面
图4-1查询功能展示图
FindAction类继承ActionSuporrt类的属性及方法,setInput()方法将输入的信息传递给FindAction类内的相应属性,getInput()方法用于返回输入值,封装的成员函数包括getlist()用于返回查询到的元组列表。图5显示可以通过姓名,性别,出生日期,email地址对联系人进行查询。
五. 运行结果
图5-1查询全部功能展示图
点击文件“编辑—查找全部”,则会弹出一个空白的查找结果界面,这是因为在程序设计中默认的是不显示所得的信息
然后点击“显示查询结果”,即可显示出全部查询结果。如图4-19:
图5-2查询全部功能展示图
参考文献:
1) Eric. Java编程思想. 第4版. 机械工业出版社, 机械工业出版社.
2) 林信良. JSP & Servlet学习笔记. 清华大学出版社, 20##年05月.
3)张峋, 杨三成. 关键技术JSP与JDBC应用详解.中国铁道出版社, 20##年11月