大学生社团信息管理系统
更新时间:2024-02-28 12:56:01 阅读量: 综合文库 文档下载
郑州科技学院
java课程设计
设计(论文)题目:所 在 院:专 业 班 级:学 生 姓 名:学 号:指 导 教 师:
大学生社团信息管理系统 信息工程学院 14通信工程2班 赵创 201451050 曾毅
2017年3月6日
郑州科技学院 Java课程设计任务书
专业 14通信工程 班级 2班 学号 201451050 姓名 赵创
一、设计题目: 二、设计任务与要求
任务:
大学生社团信息管理系统的设计
利用所学的Java知识,在图书馆查阅各种相关的书籍和个类杂志报刊以及利用互联网搜索到详尽的补充资料,来设计一个简单的大学生社团信息管理系统。
要求:了解软件eclipse和数据库的基本知识,结合自己所学的Java知识,来设计一个系统,此系统能够满足对社团人员信息的管理。
三、参考文献
[1]<<数据库系统/21世纪全国高职高专计算机应用专业规划教材>>,作者:申莉莉编,-出版社:清华大学
[2]<<管理信息系统/面向21世纪课程教材>>,作者:薛华成编,-出版社:清华大学,2004.3
[3]<< SQL SERVER 典型网站建设案例>>,宇峰编著,-北京:清华大学出版社,2006.1
[4]<<需求分析与系统设计/软件工程技术丛书>>,作者:麦沙塞克著//金芝译,-出版社:机械工业
[5]<<系统分析与设计(需求分析系列)/软件工程技术丛书>>,作者:(美)萨茨辛格等著//朱群雄等译,-出版社:机械工业
[6] <
四、设计时间
2 016 年 8 月 31 日至 2016 年 9 月 9 日
指导教师签名:
年 月 日
中 文 摘 要
利用网络和数据库技术,结合目前硬件价格普遍下跌与宽带网大力建设的有利优势,应用eclipse软件和采用MySQL数据库系统组件来构成的应用服务系统,本文开发了大学生社团管理系统这一程序。它运用方便、操作简单,效率很高。主要提供了对学生社团的管理平台。
关键词: 学生社团,eclipse,信息系统,SQL server
目 录
1项目设计思路 ................................................................................................................................ 1
1.1功能阐述 ............................................................................................................................. 1 1.2系统预览 ............................................................................................................................. 1 1.3功能结构 ............................................................................................................................. 3 1.4文件组织结构 ..................................................................................................................... 3 2数据库设计.................................................................................................................................... 4
2.1数据库设计 ......................................................................................................................... 4 2.2数据表的设计 ..................................................................................................................... 4 3公共类设计.................................................................................................................................... 5
3.1连接数据库 ......................................................................................................................... 5 3.2判断输入是否为空 ............................................................................................................. 6 4登录模块设计 ................................................................................................................................ 8
4.1登录模块概述 ..................................................................................................................... 8 4.2实现带背景的窗体 ............................................................................................................. 8 4.3登录模块实现过程 ........................................................................................................... 10 5主窗口设计.................................................................................................................................. 15
5.1主窗口概述 ....................................................................................................................... 15 5.2主窗体实现过程 ............................................................................................................... 15
5.2.1系统维护功能 ........................................................................................................ 15 5.2.2人员管理功能 ........................................................................................................ 25
参考文献......................................................................................................................................... 45
1项目设计思路
1.1功能阐述
大学生社团信息管理系统是一款辅助人员信息管理的实用性项目,根据社团的日常管理需要,大学生社团信息管理系统包括系统维护、人员管理两大模块。其中,系统维护包括添加用户、修改密码、退出系统。人员管理包括人员信息的录入、人员信息的维护,在人员信息维护中,可以实现人员信息的查询与修改。 上多种功能之间相互联系,可以满足用户的基本需求。
1.2系统预览
大学生社团信息管理系统有多个窗口组成,其中包括系统不可缺少的登录窗口,项目的主窗口,功能模块的内部窗口等。系统登录窗口效果如图1.1所示:
图1.1 大学生社团信息管理系统登录窗口
当用户输入合法的用户名的密码后,单机登录按钮,即可进入系统主窗口,运行结果如图1.2所示:
1
图1.2 大学生社团信息管理系统主窗口
本程序的主窗口中提供了进入各功能模块的按钮,通过单击这些按钮,即可进入各子模块中。各个子功能功能模块还提供了查询、修改和添加相关信息的操作,例如添加社团人员信息窗口运行的结果如图1.3所示:
图1.3 社团人员信息录入窗体
2
1.3功能结构
大学生社团信息管理系统是辅助人员信息管理而设计的,本系统的功能结构如图1.4所示:
图1.4 系统功能结构图
添加用户 修改密码 退出系统 人员信息录入 人员信息维护 系统维护 人员管理 大学生社团信息管理系统 1.4文件组织结构
大学生社团信息管理系统的根目录是大学生社团管理系统,文件组织结构图如图1.5所示。
图1.5 大学生社团信息管理系统的文件组织结构图
3
2数据库设计
2.1数据库设计
大学生社团信息管理系统采用的是SQL Server 2005数据库,数据库命名为organization,包括的数据表为information和user,表user主要用来记录用户名和密码,用于系统的登录。表information主要用来记录大学生社团人员的信息。
2.2数据表的设计
数据表设计是一个非常重要的环节,下面对系统中的数据表的结构进行分析。 1 user(登录信息表)
登录基本信息表包括了登录人员的用户名、密码,数据字段设计如表2.1所示:
表2.1 user表
字段 userId username userpassword 类型 int varchar varchar 额外 自动编号 说明 主键 用户名 密码 2 information(社团人员信息表)
社团人员信息表中保存了人员的姓名、性别、出生日期、家庭住址、联系电话、所在社团、职务等详细信息,数据表字段设计如表2.2所示:
表2.2 information表
字段 Id name sex birth address tel organization position
类型 int varchar varchar varchar varchar varchar varchar varchar 4
额外 自动编号 说明 主键 姓名 性别 出生日期 家庭住址 联系电话 所在社团 职务 3公共类设计
3.1连接数据库
任何系统的设计都离不开数据库,每一步数据库操作都需要与数据库建立连接,为了增加代码的重要性,可以将连接数据库的相关代码保存在一个类中,以便随时调用。创建类DBUtil,在该类中加载数据库驱动。在该类中定义了获取数据库连接方法getcCon(),该方法返回值为Connecttion对象。具体代码如下:
package com.zky.www.util; import java.sql.*; public class DBUtil {
private static String driverName=\private
String
URL=\g=UTF-8\
private String username=\private String password=\private Connection conn=null; static{ }
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) { }
e.printStackTrace();
public Connection getConn() {
try {
conn=DriverManager.getConnection(URL,username,password);
} catch (SQLException e) {
5
}
}
}
e.printStackTrace();
return conn;
public void closeConn(Connection conn) { } }
public static void main(String[] args) { new DBUtil().getConn(); System.out.println(\链接成功\if(conn!=null) { }
try {
conn.close(); conn=null;
} catch (SQLException e) { }
e.printStackTrace();
3.2判断输入是否为空
判断文本输入框是否为空,因此在这里建立了一个公共类StringUtil,用来判断,具体代码如下: package com.zky.www.util; public class StringUtil {
public static boolean isEmpty(String str) {
if(\
6
}
}
{
return true;
}else { }
return false;
public static boolean isNotEmpty(String str) { }
if(!\{
return true;
}else { }
return false;
7
4登录模块设计
4.1登录模块概述
运行程序,首先进入系统登录窗口。为了使窗体中的各个组件放得更加随意美观,因此本次系统设计采用了绝对布局方式,并在窗体中添加了背景图片,运行结果可以参照图1.1.
4.2实现带背景的窗体
在创建窗体时,需要向窗体中添加面板,然后在面板中添加各种组件。Swing中代表面板组件的类为JPanel,该类是以灰色为背景,并且没有任何图片,这样就不能达到很好的美观效果。因此该登录窗口所运用的就是面板的叠加,把图片添加到了JLabel中,然后把JLabel添加到面板中,并且带背景图片的面板放在了最低层,并且该面板透明度设置为不透明,这样就可以实现带背景图片的登录窗口,具体代码如下:
package com.zky.www.view;
public class LoginFrame extends JFrame{
private JLabel lbUsername=new JLabel(\用户名:\实例变量 private JTextField txtUsername=new JTextField();
private JLabel lbPassword=new JLabel(\密 码:\private JPasswordField txtPassword=new JPasswordField(); private JButton btnLogin=new JButton(\登录\
private JButton btnCancel=new JButton(\取消\
private JLabel lbTip=new JLabel(\大学生社团信息管理系统登录\
private DBUtil dbUtil=new DBUtil(); private UserDao userDao=new UserDao();
private static User mainUser=null;
LoginFrame()
{
8
ImageIcon background=new ImageIcon(\
JLabel imagLabel=new JLabel(background); this.setSize(800, 600);//设置大小
this.setLocationRelativeTo(null);//放在屏幕中间 this.setResizable(false);//不可改变大小
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭属性 Container cont=this.getContentPane(); cont.setLayout(null);//自定义布局
lbTip.setFont(new Font(\黑体\lbTip.setForeground(Color.BLUE); lbTip.setBounds(0, 30, 800, 100); cont.add(lbTip);
lbUsername.setBounds(150, 200, 100, 25);
lbUsername.setFont(new Font(\宋体\txtUsername.setBounds(280, 200, 250, 28); cont.add(lbUsername); cont.add(txtUsername);
lbPassword.setBounds(150, 290, 100, 25);
lbPassword.setFont(new Font(\宋体\txtPassword.setBounds(280, 290, 250, 28); cont.add(lbPassword); cont.add(txtPassword);
btnLogin.setBounds(210, 380, 80, 25); btnCancel.setBounds(400, 380, 80, 25);
btnLogin.addActionListener(new LoginAction()); btnLogin.setFont(new Font(\宋体\btnCancel.addActionListener(new CancelAction()); btnCancel.setFont(new Font(\宋体\cont.add(btnLogin); cont.add(btnCancel);
9
}
this.getLayeredPane().add(imagLabel,newInteger(Integer.MIN_VALUE)); }
public static User getMainUser() { }
public static void setMainUser(User mainUser) { }
public static void main(String[] args) { }
new LoginFrame();
LoginFrame.mainUser = mainUser; return mainUser;
imagLabel.setBounds(0, 0, this.getWidth(), this.getHeight()); cont.add(imagLabel);
this.setVisible(true); //可见性
4.3登录模块实现过程
登录窗口设计十分简单,有一个用户名文本框,一个密码文本框,一个登录按钮和一个取消按钮组成。下面将实现介绍登录模块的实现过程。
(1)实现用户登录操作的数据表是user,首先创建与数据表对应的JaveBeen类User,该类中属性与数据表中字段一一对应,并包含了属性的get与set方法,具体代码如下:
package com.zky.www.model; public class User {//javabean
private int userId; private String username; private String password;
public User(int userId, String username, String password) {
super();
this.userId = userId;
10
}
}
this.username = username; this.password = password;
public User(String username, String password) { }
public User() { }
public int getUserId() { }
public void setUserId(int userId) { }
public String getUsername() { }
public void setUsername(String username) { }
public String getPassword() { }
public void setPassword(String password) { }
11
super();
this.username = username; this.password = password;
super();
return userId;
this.userId = userId;
return username;
this.username = username;
return password;
this.password = password;
(2)定义类UserDao,在该类中实现按用户名与密码查询用户的方法getUser(),该方法的返回值为User对象。具体代码如下:
package com.zky.www.dao; public class UserDao {
public User checkLogin(Connection conn,User user) { }
public int modifyPassword(Connection conn, User passUser) {
int flag=-1;
String sql=\try{
PreparedStatement pstmt=conn.prepareStatement(sql);
12
User resultUser=null;
String sql=\try {
PreparedStatement pstmt=conn.prepareStatement(sql); pstmt.setString(1, user.getUsername()); pstmt.setString(2,user.getPassword()); ResultSet rs=pstmt.executeQuery(); if(rs.next()){ }
resultUser=new User();
resultUser.setUserId(rs.getInt(\resultUser.setUsername(rs.getString(\resultUser.setPassword(rs.getString(\
} catch (SQLException e) { }
return resultUser;
e.printStackTrace();
}
}
pstmt.setString(1, passUser.getPassword()); pstmt.setInt(2, passUser.getUserId()); flag=pstmt.executeUpdate();
}catch(Exception e) { } return flag;
e.printStackTrace();
(3)在登录按钮的单击事件中,调用判断用户是否合法的方法getUser(),实现如果用户名输入的用户名与密码合法将转发至系统主窗体;如果用户输入了错误的用户名与密码,则给出相应的提示。具体代码如下: private class LoginAction implements ActionListener
{
public void actionPerformed(ActionEvent e) {
String username=txtUsername.getText().trim(); String password=txtPassword.getText().trim(); if(StringUtil.isEmpty(username)) { }
if(StringUtil.isEmpty(password)) { }
User user=new User(username,password); Connection conn=dbUtil.getConn();
13
JOptionPane.showMessageDialog(null,\用户名不能为空!\return ;
JOptionPane.showMessageDialog(null,\密码不能为空!\return;
}
mainUser=userDao.checkLogin(conn, user); }
dbUtil.closeConn(conn);//关闭连接 if(mainUser!=null) {
MainFrame mainFrame=new MainFrame(); LoginFrame.this.setVisible(false);
}else{ }
JOptionPane.showMessageDialog(null, \用户名或密码错误!\txtUsername.setText(\txtPassword.setText(\txtUsername.requestFocus();
(4)在取消按钮的单击事件中,用户名文本框与密码文本框里的内容将设置为空,用空文本代替之前输入的内容。具体的代码如下: private class CancelAction implements ActionListener
{ }
}
public void actionPerformed(ActionEvent arg0) { txtUsername.setText(\txtPassword.setText(\txtUsername.requestFocus();
14
5主窗口设计
5.1主窗口概述
成功登录系统后,即可进入程序的主窗体。在主窗口中添加了菜单栏,在菜单栏中添加菜单,菜单中有包括了二级菜单,主窗口运行结果如图5.1所示。
图5.1 程序主窗体运行结果
5.2主窗体实现过程
5.2.1系统维护功能
(1)添加用户
当单击添加用户,则系统自动跳出添加用户窗口,添加完成以后,对应的数据库中的User表中会添加相应的用户名与密码,此用户名与密码可用于登录该大学生社团信息管理系统的登录。程序运行的结果如图5.2所示,相应的代码如下:
15
图5.2 添加用户窗体运行结果
添加用户相应代码:
package com.zky.www.view;
public class addUser extends JInternalFrame {
private JPanel jContentPane = null; private JLabel lbTip = null; private JLabel name = null; private JTextField inputName = null; private JLabel password = null;
private JPasswordField inputPassword = null; private JLabel passwordTwo=null;
private JPasswordField inputPasswordTwo=null; private JButton btnAdd = null; private JButton btnCancel = null; public addUser() { }
private void initialize() {
this.setBounds(new Rectangle(150, 150, 500, 400));
16
super(); initialize();
}
this.setIconifiable(true); this.setClosable(true); this.setTitle(\添加新用户\
this.setContentPane(getJContentPane()); this.setVisible(true);
private JPanel getJContentPane() {
if (jContentPane == null) {
password = new JLabel(\密码:\password.setFont(new Font(\宋体\password.setBounds(new Rectangle(45, 130, 93, 34)); passwordTwo=new JLabel(\再次确认:\passwordTwo.setFont(new Font(\宋体\passwordTwo.setBounds(new Rectangle(36, 177, 150, 34)); name = new JLabel(\姓名:\name.setFont(new Font(\宋体\name.setBounds(new Rectangle(44, 83, 90, 29)); lbTip = new JLabel(\添加新用户\lbTip.setBounds(new Rectangle(0, 0, 500, 80)); lbTip.setForeground(Color.blue);
lbTip.setFont(new Font(\黑体\jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.add(lbTip, null); jContentPane.add(name, null); jContentPane.add(passwordTwo, null);
jContentPane.add(getTxtBookTypeName(), null); jContentPane.add(password, null);
jContentPane.add(getTxtBookTypeDesc(), null); jContentPane.add(getPasswordTwo(), null);
17
}
}
jContentPane.add(getBtnAdd(), null); jContentPane.add(getBtnCancel(), null);
return jContentPane;
private JTextField getPasswordTwo() { }
private JTextField getTxtBookTypeName() { }
private JTextField getTxtBookTypeDesc() { }
private JButton getBtnAdd() {
if (btnAdd == null) {
btnAdd = new JButton(\添加\
18
if (inputPasswordTwo == null) { }
return inputPasswordTwo;
inputPasswordTwo = new JPasswordField();
inputPasswordTwo.setBounds(new Rectangle(170, 177, 170, 25));
if (inputName == null) { }
return inputName;
inputName = new JTextField();
inputName.setBounds(new Rectangle(170, 83, 170, 25));
if (inputPassword == null) { }
return inputPassword;
inputPassword = new JPasswordField();
inputPassword.setBounds(new Rectangle(170, 130, 170, 25));
\
btnAdd.setFont(new Font(\宋体\btnAdd.setBounds(new Rectangle(120, 240,70, 30)); btnAdd.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { String Name=inputName.getText().trim(); String Password=inputPassword.getText().trim(); String PasswordTwo=inputPasswordTwo.getText().trim(); if(StringUtil.isEmpty(Name)) { JOptionPane.showMessageDialog(null,\姓名不能为空!\ inputName.requestFocus(); return;
}
if(StringUtil.isEmpty(Password)) { JOptionPane.showMessageDialog(null,\密码不能为空!\ inputPassword.requestFocus(); return;
}
if(StringUtil.isEmpty(PasswordTwo)) {
JOptionPane.showMessageDialog(null,\请再次输入密码! inputPasswordTwo.requestFocus(); return;
}
if(Password.equals(PasswordTwo)) {
BookType bookType=new BookType(Name,Password);
int flag=new BookTypeDao().addBookType(bookType);
19
if(flag>0) {
JOptionPane.showMessageDialog(null, \添加成功!\inputName.setText(\inputPassword.setText(\inputPasswordTwo.setText(\inputName.requestFocus();
}else{ } } else{
JOptionPane.showMessageDialog(null, \两次密码输入不JOptionPane.showMessageDialog(null, \添加失败!\
一致,请重新输入!\
}
}
});
}
}
inputPassword.setText(\inputPasswordTwo.setText(\inputPassword.requestFocus(); return;
return btnAdd;
private JButton getBtnCancel() {
if (btnCancel == null) {
20
}
}
}
btnCancel = new JButton();
btnCancel.setBounds(new Rectangle(250, 240, 70, 30)); btnCancel.setText(\取消\
btnCancel.setFont(new Font(\宋体\
return btnCancel;
(2)修改密码
当单击修改密码,则系统会运行相应的代码,出现修改密码窗口,原密码就是登录系统的密码,新密码是重新定义的密码,修改密码之后,旧密码不能登录系统,应该用新密码登录该系统,在修改密码过程中,两次新密码必须一致,否则不能修改密码。系统运行结果如图5.3所示,相应的代码如下。
图5.3 修改密码窗体运行结果
修改密码相应代码:
package com.zky.www.view;
21
public class ModifyPassIFrame extends JInternalFrame{
private JLabel lboldPassword=new JLabel(\旧密码:\
private JPasswordField txtoldPassword=new JPasswordField(); private JLabel lbnewPassword=new JLabel(\新密码:\
private JPasswordField txtnewPassword=new JPasswordField(); private JLabel lbconfirmPassword=new JLabel(\确认密码:\private JPasswordField txtconfirmPassword=new JPasswordField(); private JButton btnModify=new JButton(\修改\
private JButton btnCancel=new JButton(\取消\
private User user=LoginFrame.getMainUser();//从LoginFrame中获取mainUser的值
private DBUtil dbUtil=new DBUtil(); ModifyPassIFrame() {
this.setSize(320, 300);
this.setLocation(240, 150); this.setClosable(true); this.setIconifiable(true); this.setTitle(\修改密码\
Container cont=this.getContentPane(); cont.setLayout(null);
lboldPassword.setBounds(50, 50, 60, 25); txtoldPassword.setBounds(120, 50, 120, 25); cont.add(lboldPassword); cont.add(txtoldPassword);
lbnewPassword.setBounds(50, 85, 60, 25); txtnewPassword.setBounds(120, 85, 120, 25); cont.add(lbnewPassword); cont.add(txtnewPassword);
lbconfirmPassword.setBounds(50, 120, 60, 25);
22
txtconfirmPassword.setBounds(120, 120, 120, 25); cont.add(lbconfirmPassword); cont.add(txtconfirmPassword); btnModify.setBounds(85, 190, 60, 25); btnCancel.setBounds(180, 190, 60, 25);
btnModify.addActionListener(new ModifyPasswordAction()); cont.add(btnModify); cont.add(btnCancel); this.setVisible(true); }
private class ModifyPasswordAction implements ActionListener{
public void actionPerformed(ActionEvent e) {
String oldPassword=txtoldPassword.getText().trim(); String newPassword=txtnewPassword.getText().trim(); String confirmPassword=txtconfirmPassword.getText().trim(); if(StringUtil.isEmpty(oldPassword)) { }
JOptionPane.showMessageDialog(null,\旧密码不能为空!\txtoldPassword.requestFocus(); return ;
if(StringUtil.isEmpty(newPassword)) { }
if(StringUtil.isEmpty(confirmPassword)) {
JOptionPane.showMessageDialog(null,\确认密码不能为空!\txtconfirmPassword.requestFocus();
23
JOptionPane.showMessageDialog(null,\新密码不能为空!\txtnewPassword.requestFocus(); return ;
}
}
return ;
if(oldPassword.equals(user.getPassword())) {
if(newPassword.equals(confirmPassword)) {
Connection conn=dbUtil.getConn(); User passUser=new User(); passUser.setUserId(user.getUserId()); passUser.setPassword(newPassword);
int i=new UserDao().modifyPassword(conn,passUser); if(i>0) { }
JOptionPane.showMessageDialog(null,\密码修改成功!\txtoldPassword.setText(\txtnewPassword.setText(\txtconfirmPassword.setText(%user.setPassword(newPassword);
}else{ }
JOptionPane.showMessageDialog(null,\两次密码输入不一致!\txtnewPassword.setText(\txtconfirmPassword.setText(\txtnewPassword.requestFocus();
}else{JOptionPane.showMessageDialog(null,\旧密码输入不正确!\ }
txtoldPassword.setText(\txtoldPassword.requestFocus();
} }
(3)退出系统
24
当单击退出系统,该系统就会直接退出,相应的代码如下: private class ExitSystemAction implements ActionListener
{
}
}
public void actionPerformed(ActionEvent arg0) { System.exit(0);
5.2.2人员管理功能
(1)人员信息录入
单击人员信息录入,系统会跳出人员信息录入窗口,程序运行结果如图5.4所示:
图5.4 人员信息录入窗体运行结果
当用户单击录入按钮,则信息则会添加到数据库的nformation表中,当单击取消按钮,则文本框中的内容全部为空,可以重新输入。相应的代码如下:
人员信息录入代码: package com.zky.www.view;
public class Addpeople extends JInternalFrame {
private JLabel lbTip = new JLabel(\社团人员信息录入\private JLabel name = new JLabel(\姓名:\private JTextField inputName = new JTextField();
25
private JLabel sex = new JLabel(\性别:\private ButtonGroup group=new ButtonGroup(); private JRadioButton JRB1=new JRadioButton(\男\private JRadioButton JRB2=new JRadioButton(\女\private JLabel brithday=new JLabel(\出生日期:\private Choice choiceOne=new Choice(); private Choice choiceTwo=new Choice(); private Choice choiceThree=new Choice(); private JLabel address=new JLabel(\家庭住址:\private JTextField inputAdress=new JTextField(); private JLabel year=new JLabel(\年\private JLabel month=new JLabel(\月\private JLabel day=new JLabel(\日\private JLabel tel=new JLabel(\联系电话:\private JTextField inputTel=new JTextField(); private JLabel organization=new JLabel(\所在社团:\
private Choice choiceFour=new Choice();
private JLabel position=new JLabel(\担任职务:\private Choice choiceFive=new Choice(); private Button btnAdd=new Button(\录入\private Button btnCancel=new Button(\取消\Addpeople() {
JRB1.setActionCommand(\男\JRB2.setActionCommand(\女\this.setBounds(50, 90, 600, 450);; this.setTitle(\信息录入\this.setIconifiable(true); this.setClosable(true);
Container con=this.getContentPane(); con.setLayout(null);
26
lbTip.setBounds(0, 0, 600, 50); con.add(lbTip);
name.setBounds(80, 80, 50, 25); con.add(name);
inputName.setBounds(160, 80, 150, 23); con.add(inputName); sex.setBounds(80, 115, 50, 25); JRB1.setBounds(160, 115, 50, 25); JRB2.setBounds(260,115, 50, 25); con.add(sex); con.add(JRB1); con.add(JRB2);
brithday.setBounds(80, 150, 90, 25); choiceOne.setBounds(180, 150, 70, 25); year.setBounds(260, 150, 40, 25); choiceTwo.setBounds(290, 150, 70, 25); month.setBounds(370, 150, 40, 25); choiceThree.setBounds(400, 150, 70, 25); day.setBounds(500, 150, 30, 25); con.add(brithday); con.add(choiceOne); con.add(choiceTwo); con.add(choiceThree); con.add(year); con.add(month); con.add(day);
for(int i=1990;i<=2017;i++)
choiceOne.add(String.valueOf(i));
27
for(int j=1;j<=12;j++)
choiceTwo.add(String.valueOf(j));
for(int k=1;k<=31;k++)
choiceThree.add(String.valueOf(k));
group.add(JRB1); group.add(JRB2);
address.setBounds(80, 190, 80, 25); inputAdress.setBounds(180, 190, 150, 23); con.add(address); con.add(inputAdress); tel.setBounds(80, 230, 80, 25); inputTel.setBounds(180, 230, 150, 23); con.add(tel); con.add(inputTel);
organization.setBounds(80, 270, 80, 25); position.setBounds(80, 310, 80, 25); choiceFour.setBounds(180, 270, 150, 30); choiceFive.setBounds(180, 310, 150, 30); con.add(choiceFour); con.add(choiceFive); con.add(organization); con.add(position);
choiceFour.add(\青年志愿者协会\choiceFour.add(\篮球协会\choiceFour.add(\英语协会\choiceFour.add(\校学生会\choiceFive.add(\会长\choiceFive.add(\副会长\choiceFive.add(\社团成员\btnAdd.setBounds(150, 355, 60, 30); btnCancel.setBounds(270, 355, 60, 30);
28
con.add(btnAdd); con.add(btnCancel);
btnAdd.addActionListener(new ActionListener() {
private int Id;
public void actionPerformed(ActionEvent arg0) { String Name=inputName.getText().trim();
String xingbie=group.getSelection().getActionCommand(); String brith=choiceOne.getSelectedItem()+\年
\月\日\
String address=inputAdress.getText().trim(); String tel=(String)inputTel.getText().trim(); String organization=choiceFour.getSelectedItem(); String position=choiceFive.getSelectedItem(); if(StringUtil.isEmpty(Name)) { }
if(StringUtil.isEmpty(address)) { }
if(StringUtil.isEmpty(tel)) { }
peopleInformation information=new
29
JOptionPane.showMessageDialog(null,\姓名不能为空!\inputName.requestFocus(); return;
JOptionPane.showMessageDialog(null,\住址不能为空!\inputTel.requestFocus(); return;
JOptionPane.showMessageDialog(null,\电话号码不能为空!\inputTel.requestFocus(); return;
peopleInformation(Id,Name,xingbie,brith,address,tel,organization,position); }
}
});
btnCancel.addActionListener(new ActionListener(){ });
this.setVisible(true);
public void actionPerformed(ActionEvent arg0) { }
}
int flag=new addInformation().addBookType(information); if(flag>0) {
JOptionPane.showMessageDialog(null, \添加成功!\inputName.setText(\inputAdress.setText(\inputTel.setText(\inputName.requestFocus();
}else{ }
JOptionPane.showMessageDialog(null, \添加失败!\
创建与information表对应的JaveBeen对象peopleInformation,该类中的属性与information表中的字段一一对应,并包括了各属性的get与set方法,具体代码如下:
package com.zky.www.model;
public class peopleInformation {
private int Id;
private String name; private String sex; private String address;
30
private String brithday; private String tel; private String organization; private String position; private String paint; private String brithYear; private String brithMonth; private String brithDay; public peopleInformation(int Id) { }
public peopleInformation(int Id,String name) { }
public peopleInformation(int Id,String name,String sex,String brithday,String address,String tel,String organization,String position) {
super(); this.Id=Id;
super(); this.Id=Id; this.name=name;
super(); this.Id=Id; this.name=name; this.sex=sex;
this.brithday=brithday; this.address=address; this.tel=tel;
31
}
this.organization=organization; this.position=position;
public peopleInformation(String name,String sex,String brithday,String address,String tel,String organization,String position) { super();
this.name=name; this.sex=sex;
this.brithday=brithday; this.address=address; this.tel=tel;
this.organization=organization; this.position=position;
}
public peopleInformation(String name) {
this.name=name;
}
public peopleInformation() { super();
}
public int getId() { return Id;
}
public void setId(int id) { Id = id;
}
public String getName() {
32
return name;
}
public void setName(String name) { this.name = name;
}
public String getSex() { return sex;
}
public void setSex(String sex) { this.sex = sex;
}
public String getAddress() { return address;
}
public void setAddress(String address) { this.address = address;
}
public String getBrithday() { return brithday;
}
public void setBrithday(String brithday) { this.brithday = brithday;
}
public String getTel() { return tel;
}
public void setTel(String tel) { this.tel = tel;
}
public String getOrganization() {
33
}
return organization;
public void setOrganization(String organization) { }
public String getPosition() { }
public void setPosition(String position) { }
public String getPaint() { }
public void setPaint(String paint) { }
public String getBrithYear() { }
public void setBrithYear(String brithYear) { }
public String getBrithMonth() { }
public void setBrithMonth(String brithMonth) { }
public String getBrithDay() {
34
this.organization = organization;
return position;
this.position = position;
return paint;
this.paint = paint;
return brithYear;
this.brithYear = brithYear;
return brithMonth;
this.brithMonth = brithMonth;
}
return brithDay;
public void setBrithDay(String brithDay) { } }
(2)人员信息维护
当单击人员信息维护,则系统会跳出人员信息维护窗口。具体运行的结果如图5.5所示。
this.brithDay = brithDay;
图5.5 人员信息维护窗体运行结果
该窗体实现了数据库中人员信息的修改,查询,删除等功能。当该窗口运行,表格中就会显示所有社团人员的信息,当单击任意一名社团人员信息,则表格下面的文本框中就会对应显示其信息,在任意文本框中修改信息,单击修改,则社团人员信息就会被修改,如果单击删除按钮,则该社团人员的信息就会被删除。
还可以在表格上方的文本框中输入姓名关键字,单击查询按钮,则表格中就会显示查询的结果。相应的具体代码如下所示: 人员信息维护代码: package com.zky.www.view;
35
public class bookTypeQMDIFrame extends JInternalFrame {
protected static final peopleInformation peopleinformation = null; private JPanel jContentPane = null; private JLabel lbTip = null; private JLabel lbSBookName = null; private JTextField txtSBookTypeName = null; private JButton btnQuery = null; private JScrollPane scroll = null; private JTable table = null; private JLabel Id = null;
private JTextField txtBookTypeId = null; private JLabel Name = null;
private JTextField txtBookTypeName = null; private JLabel lbBookTypeDesc = null; private JButton btnModify = null; private JButton btnDelete = null;
private JTextField sexInput=new JTextField(); private JLabel brithday=new JLabel(\出生日期:\private JTextField brithInput=new JTextField(); private ButtonGroup group=new ButtonGroup(); private JLabel address=new JLabel(\家庭住址:\private JTextField inputAdress=new JTextField(); private JLabel tel=new JLabel(\联系电话:\private JTextField inputTel=new JTextField(); private JLabel organization=new JLabel(\所在社团:\
private JTextField organizationInput=new JTextField();
private JLabel position=new JLabel(\担任职务:\private JTextField positionInput=new JTextField();
private DefaultTableModel model=new DefaultTableModel(){
public boolean isCellEditable(int row, int column) {
36
};
};
return false;
public bookTypeQMDIFrame() { }
private void initialize() { }
private JPanel getJContentPane() {
if (jContentPane == null) {
lbBookTypeDesc = new JLabel();
lbBookTypeDesc.setBounds(new Rectangle(8, 315, 67, 28)); lbBookTypeDesc.setText(\性别:\sexInput.setBounds(80, 315, 130, 26); brithday.setBounds(8, 355, 67, 28); brithInput.setBounds(80, 355, 130, 26); this.setBounds(new Rectangle(110, 20, 600, 580)); this.setTitle(\人员信息维护\this.setIconifiable(true); this.setClosable(true);
this.setContentPane(getJContentPane()); this.setVisible(true); super(); initialize();
address.setBounds(8, 390, 67, 28);
inputAdress.setBounds(80, 390, 130, 26); tel.setBounds(250, 315, 67, 28); inputTel.setBounds(335, 315, 130, 26); organization.setBounds(8, 432, 67, 28); organizationInput.setBounds(80, 432, 130, 26); position.setBounds(250, 355, 67, 28);
37
positionInput.setBounds(335, 355, 130, 26); Name = new JLabel();
Name.setBounds(new Rectangle(250, 280, 67, 28)); Name.setText(\姓名:\Id = new JLabel();
Id.setBounds(new Rectangle(7, 280, 68, 29)); Id.setText(\编号:\
lbSBookName = new JLabel();
lbSBookName.setBounds(new Rectangle(9, 58, 146, 25)); lbSBookName.setText(\请输入查询关键字:\lbTip = new JLabel(\人员信息查询\lbTip.setBounds(new Rectangle(0, 0, 600, 35)); lbTip.setFont(new Font(\黑体\jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.add(lbTip, null); jContentPane.add(lbSBookName, null);
jContentPane.add(getTxtSBookTypeName(), null); jContentPane.add(sexInput, null); jContentPane.add(brithday, null); jContentPane.add(brithInput, null); jContentPane.add(address, null); jContentPane.add(inputAdress, null); jContentPane.add(getBtnQuery(), null); jContentPane.add(getScroll(), null); jContentPane.add(Id, null);
jContentPane.add(getTxtBookTypeId(), null); jContentPane.add(Name, null);
jContentPane.add(getTxtBookTypeName(), null); jContentPane.add(lbBookTypeDesc, null);
38
}
}
jContentPane.add(tel, null); jContentPane.add(inputTel, null); jContentPane.add(organization, null); jContentPane.add(organizationInput, null); jContentPane.add(position, null); jContentPane.add(positionInput, null); jContentPane.add(getBtnModify(), null); jContentPane.add(getBtnDelete(), null);
return jContentPane;
private JTextField getTxtSBookTypeName() { }
if (txtSBookTypeName == null) { }
return txtSBookTypeName;
txtSBookTypeName = new JTextField();
txtSBookTypeName.setBounds(new Rectangle(161, 57, 148, 29));
private JButton getBtnQuery() {
if (btnQuery == null) {
btnQuery = new JButton();
btnQuery.setBounds(new Rectangle(350, 58, 67, 25)); btnQuery.setText(\查询\
btnQuery.addActionListener(new ActionListener(){
private peopleInformation peopleinformation;
public void actionPerformed(ActionEvent arg0) {
String name=txtSBookTypeName.getText().trim();
peopleInformation booktype=new peopleInformation(name); model.setDataVector(new bookTypeQMDIFrame().getDatas(booktype),
39
new bookTypeQMDIFrame().getTitles());
}
}
});
}
return btnQuery;
private JScrollPane getScroll() { }
private JTable getTable() {
if (table == null) {
table = new JTable();
table.getTableHeader().setReorderingAllowed(false); table.getTableHeader().setResizingAllowed(false); table.setModel(model);
model.setDataVector(this.getDatas(new peopleInformation()), this.getTitles()); table.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e) {
int selectedRow=table.getSelectedRow();
int bookTypeId=(Integer)table.getValueAt(selectedRow, 0); String bookTypeName=(String)table.getValueAt(selectedRow, 1); String sex=(String)table.getValueAt(selectedRow, 2); String brith=(String)table.getValueAt(selectedRow, 3); String address=(String)table.getValueAt(selectedRow, 4); String tel=(String)table.getValueAt(selectedRow, 5); String organization=(String)table.getValueAt(selectedRow, 6);
40
if (scroll == null) { }
return scroll;
scroll = new JScrollPane();
scroll.setBounds(new Rectangle(5, 100, 580, 157)); scroll.setViewportView(getTable());
}
}
});
}
String position=(String)table.getValueAt(selectedRow, 7); txtBookTypeId.setText(Integer.toString(bookTypeId)); txtBookTypeName.setText(bookTypeName); sexInput.setText(sex); brithInput.setText(brith);
organizationInput.setText(organization); positionInput.setText(position); inputAdress.setText(address); inputTel.setText(tel);
return table;
private Vector getTitles() {
Vector v=new Vector(); v.add(\编号\v.add(\姓名\v.add(\性别\v.add(\出生日期\v.add(\家庭住址\v.add(\联系电话\v.add(\所加社团\v.add(\社团职务\return v;
}
private Vector getDatas(peopleInformation peopleinformation) {
return new BookTypeDao().getDatas(peopleinformation);
41
}
private JTextField getTxtBookTypeId() { }
private JTextField getTxtBookTypeName() { }
private JButton getBtnModify() {
if (btnModify == null) {
btnModify = new JButton();
btnModify.setBounds(new Rectangle(300, 415, 71, 25)); btnModify.setText(\修改\
btnModify.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
String strId=txtBookTypeId.getText().trim(); String name=txtBookTypeName.getText().trim(); String sex=sexInput.getText().trim(); String brith=brithInput.getText().trim(); String address=inputAdress.getText().trim(); String tel=inputTel.getText().trim();
String organization=organizationInput.getText().trim();
42
if (txtBookTypeId == null) { }
return txtBookTypeId;
txtBookTypeId = new JTextField();
txtBookTypeId.setBounds(new Rectangle(80, 280, 130, 26)); txtBookTypeId.setEditable(false);
if (txtBookTypeName == null) { }
return txtBookTypeName;
txtBookTypeName = new JTextField();
txtBookTypeName.setBounds(new Rectangle(335, 280, 130, 26));
\
String position=positionInput.getText().trim();
if(StringUtil.isEmpty(strId)) {
JOptionPane.showMessageDialog(null, \请您选择要修改的记录!
}
return ;
if(StringUtil.isEmpty(name)) { }
int id=Integer.parseInt(strId);
peopleInformation peopleinformation=new peopleInformation( id,
JOptionPane.showMessageDialog(null, \姓名不能为空!\return ;
name, sex, brith, address, tel, organization, position);
int flag=new BookTypeDao().modifyBookType(peopleinformation); if(flag>0)
{JOptionPane.showMessageDialog(null, \修改成功!\
model.setDataVector(new bookTypeQMDIFrame().getDatas(new
peopleInformation()), new bookTypeQMDIFrame().getTitles());
}
});
}
}else { }
JOptionPane.showMessageDialog(null, \修改失败!\
return btnModify;
43
}
private JButton getBtnDelete() {
if (btnDelete == null) {
btnDelete = new JButton();
btnDelete.setBounds(new Rectangle(430, 415, 65, 25)); btnDelete.setText(\删除\
btnDelete.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
String strId=txtBookTypeId.getText().trim(); if(StringUtil.isEmpty(strId)) { }
int id=Integer.parseInt(strId);
peopleInformation peopleinformation=new peopleInformation(id); int flag=new BookTypeDao().deleteBookType(peopleinformation); if(flag>0) {
JOptionPane.showMessageDialog(null, \删除成功!\model.setDataVector(new bookTypeQMDIFrame().getDatas(new JOptionPane.showMessageDialog(null, \请选择删除的记录!\return ;
peopleInformation()), new bookTypeQMDIFrame().getTitles()); }
44
}
}
} } });
}else{
JOptionPane.showMessageDialog(null, \删除失败!\
return btnDelete;
参考文献
[1]<<数据库系统/21世纪全国高职高专计算机应用专业规划教材>>,作者:申莉莉编,-出版社:清华大学
[2]<<管理信息系统/面向21世纪课程教材>>,作者:薛华成编,-出版社:清华大学,2004.3
[3]<< SQL SERVER 典型网站建设案例>>,宇峰编著,-北京:清华大学出版社,2006.1
[4]<<需求分析与系统设计/软件工程技术丛书>>,作者:麦沙塞克著//金芝译,-出版社:机械工业
[5]<<系统分析与设计(需求分析系列)/软件工程技术丛书>>,作者:(美)萨茨辛格等著//朱群雄等译,-出版社:机械工业
[6] <
45
正在阅读:
大学生社团信息管理系统02-28
6、项目监理工作考核管理办法05-17
亲子关系调查问卷12-09
我的时间 高考满分作文02-22
12MW抽汽凝汽式汽轮机设计说明书09-30
传播学期末考试试卷(含答案)06-29
《浅谈公立医院改革》08-19
周恩来 - 图文06-29
运用联想丰富写作内容07-09
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 社团
- 管理系统
- 大学生
- 信息