Java语言课程设计说明书.doc
Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateJava语言课程设计说明书天津城市建设学院课程考核分析表学 号 1407070229 Java语言程序设计课程设计 课程设计说明书天津城建大学教学改革项目管理信息系统起止日期: 2016 年 1 月 4 日 至 2016 年 1 月 10 日学生姓名赵文豪班级软件2班成绩指导教师(签字)计算机与信息工程学院软件工程系年 月 日1、需求分析 程序的功能:系统注册:用id和密码注册;系统登陆:用已注册的id和密码来登录;录入项目信息:在主界面的面板上显示所有已添加的项目信息,而且项目信息不允许重复,判断关键字为学号;添加项目信息:在已有的项目记录里添加新的项目信息。点击主界面的添加按钮,跳到添加界面,用户从键盘输入项目信息,完成后点击确定添加按钮,显示“添加成功”字样,系统将信息添加到数据库表格中,并通过Vector在主面板上显示。删除项目记录:在已有项目记录中删除,用户从键盘输入要删除的id,成功删除后更新到表中。修改项目记录:在已有记录中修改某一个项目的记录,输入要修改的id,判断记录中是否存在该id,若存在,显示修改界面供用户修改。查询项目记录:包括按id查询和按项目类型查询。在指定位置输入所需查询id,点击“按id查询”,面板上显示所查询的信息;或者选择所需查询的项目类型,点击“按类型查询”,面板上显示信息;退出系统:点击“退出”按钮,退出系统;输入输出的要求:注册登录添加等各种操作时输入的id,密码,项目记录信息都为String类型。测试数据:注册成功后点击到相应登陆页面,按提示输入已注册的id,提示登陆成功后自动跳转main系统页面,按提示选择所需增、删、改、查各种功能,所需信息会显示在main的主面板上。2、概要设计 注册并成功登陆系统后,出现项目管理信息界面,主面板显示所有已有项目信息,可以对教学改革的各种项目信息进行增加,删除,修改,查询,进入相应界面进行信息管理,完成后退出系统界面。 注册 登陆退出系统分别按照id和选题类型查询项目信息删除已有项目信息修改项目信息增加项目信息3、 详细设计3.1. 创建Teacher类,User类,设置变量及对应方法 public class Teacher private String title; private String date; private String type; private String money; private String time; Getter and Setter并创建构造函数; public class Users public int id;private String password; Getter and Setter并创建构造函数;3.2. Teacher管理类TeacherDao,创建对应方法,实现对Teacher对象的操作(显示主面板统计所有项目信息、增、删、改、查等功能)供view包里的对象调用。User管理类UserDao及对应方法,创建注册界面对象操作的方法,供view包里的Login类使用。3.3 util包里的DBCon类,用来连接关闭数据库public class DBCon public static Connection getCon()Connection con=null;try Class.forName("com.mysql.jdbc.Driver");con = DriverManager.getConnection("jdbc:mysql:/localhost:3306/test", "root", "admin"); catch (ClassNotFoundException e) / TODO Auto-generated catch blocke.printStackTrace(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return con;3.4. View包里创建AddTea,Delect,Login,Regist,Update类,实现注册界面,登陆界面和所有对项目信息,使用者信息管理的界面,同时创建Main对象,调用方法,实现项目所有基本内容管理。3.5 添加项目:选择用鼠标控制按钮“添加”,从Main里选择“添加”项目,获得对象,进入添加界面按要求输入信息,项目类型、结题时间从下拉菜单中选择,添加完毕后用集合Vector同步到Main的面板上。3.6删除项目:在已有项目记录中删除,要求用户从键盘输入要删除的id,遍历表格是否有输入id的项目信息,如果存在则自动删除,没有则提示删除失败,成功删除后更新到表中。3.7修改项目:传递对象到修改方法,要求用户输入要修改的id,遍历记录中是否存在该id,若存在,显示修改界面供用户修改。修改成功后获得对象,使用Vector同步到主面板上。3.8查询项目记录:包括按id查询和按项目类型查询。在指定位置输入所需查询id,点击“按id查询”,面板上显示所查询的信息;或者选择所需查询的项目类型,点击“按类型查询”,面板上显示信息;3.9退出系统:使用System.exit(0);4、 调试分析4.1. String sql="select * from teacher where id=?,name1=?,teacher=?,title=?,date1=?,type=?,money=?,time=?"String sql="update teacher set name1=?,teacher=?,title=?,date1=?,type=?,money=?,time=? where id=?"String sql="delete from teacher where id=?"String sql="insert into teacher(id,name1,teacher,title,date1,type,money,time)value(?,?,?,?,?,?,?,?)"一定要写对,不然运行时会出现很多错误4.2 数据的增删改查操作,实现数据库连接,需要将有关的SQL语句传入,在实现完有关项目信息的操作之后要关闭数据库操作;4.3 在得到所有的数据这一操作中,用到了集合类Vector,将数据添加到集合Vector中实现对信息的浏览;4.4 PreparedStatement在实现数据的过程中,需要用?占据位置,之后在对其依次赋值,PreparedStatement可实现对部分数据的传值5. 核心源程序清单和执行结果/类TeacherDaopublic class TeacherDao/增加public int addTea(Teacher teacher)Connection con=DBCon.getCon();String sql="insert into teacher(id,name1,teacher,title,date1,type,money,time)value(?,?,?,?,?,?,?,?)"int count=0;PreparedStatement prest=null;Statement st=null;ResultSet rs=null;try prest=con.prepareStatement(sql);prest.setString(1, teacher.getId();prest.setString(2, teacher.getName();prest.setString(3, teacher.getTeacher();prest.setString(4, teacher.getTitle();prest.setString(5, teacher.getDate();prest.setString(6, teacher.getType();prest.setString(7, teacher.getMoney();prest.setString(8, teacher.getTime();count=prest.executeUpdate(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();DBCon.Close(st, con, rs);return count;/删除/id,name,teacher,title,date,type,money,timepublic static int Delect(Teacher teacher1)Connection con=DBCon.getCon();String sql="delete from teacher where id=?"PreparedStatement prest=null;int count=0;try prest = con.prepareStatement(sql);prest.setString(1,teacher1.getId();count=prest.executeUpdate(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();DBCon.Close(prest, con);return count; /修改/id,name,teacher,title,date,type,money,timepublic int updateTeacher(Teacher t,String id) / TODO Auto-generated method stubConnection con=DBCon.getCon();String sql="update teacher set name1=?,teacher=?,title=?,date1=?,type=?,money=?,time=? where id=?"PreparedStatement prest=null;int count=0;try prest = con.prepareStatement(sql);prest.setString(1,t.getName();prest.setString(2,t.getTeacher();prest.setString(3,t.getTitle();prest.setString(4,t.getDate();prest.setString(5,t.getType();prest.setString(6,t.getMoney();prest.setString(7,t.getTime();prest.setString(8,t.getId();count=prest.executeUpdate(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();finallyDBCon.Close(prest, con);return count;/通过id查询信息/id,name,teacher,title,date,type,money,timepublic Vector getAllTea2(String id)Vector v=new Vector();Connection con=DBCon.getCon();PreparedStatement prest=null;ResultSet rs=null;String sql="select * from teacher where id=?"try prest=con.prepareStatement(sql); prest.setString(1, id); rs=prest.executeQuery();while(rs.next()Vector<String> v1=new Vector<String>();v1.add(rs.getString(1);v1.add(rs.getString(2);v1.add(rs.getString(3);v1.add(rs.getString(4);v1.add(rs.getString(5);v1.add(rs.getString(6);v1.add(rs.getString(7);v1.add(rs.getString(8);v.add(v1); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return v;/通过类型查找信息public Vector findkind(String type)Vector v=new Vector();Connection con=DBCon.getCon();String sql="select * from teacher where type=?"PreparedStatement prest=null;ResultSet rs=null;try prest=con.prepareStatement(sql);prest.setString(1, type);rs=prest.executeQuery();while(rs.next()Vector<String> v1=new Vector<String>(); v1.add(String.valueOf(rs.getInt(1);v1.add(rs.getString(2);v1.add(rs.getString(3);v1.add(rs.getString(4);v1.add(rs.getString(5);v1.add(rs.getString(6);v1.add(rs.getString(7);v1.add(rs.getString(8);v.add(v1); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();DBCon.close(con, prest, rs);return v;/遍历所有信息public Vector findall() / TODO Auto-generated method stubVector v=new Vector();Connection con=DBCon.getCon();String sql="select * from teacher "PreparedStatement prest=null;ResultSet rs=null;try prest=con.prepareStatement(sql);rs=prest.executeQuery();while(rs.next()Vector<String> vc=new Vector<String>(); vc.add(rs.getString(1);vc.add(rs.getString(2);vc.add(rs.getString(3);vc.add(rs.getString(4);vc.add(rs.getString(5);vc.add(rs.getString(6);vc.add(rs.getString(7);vc.add(rs.getString(8);v.add(vc); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();DBCon.close(con, prest, rs);return v;/类DBConpublic class DBCon public static Connection getCon()Connection con=null;try Class.forName("com.mysql.jdbc.Driver");con = DriverManager.getConnection("jdbc:mysql:/localhost:3306/test", "root", "admin"); catch (ClassNotFoundException e) / TODO Auto-generated catch blocke.printStackTrace(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();return con;public static void Close(Statement st,Connection con,ResultSet rs) / TODO Auto-generated method stubif(rs!=null)try rs.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();if(st!=null)try st.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();if(con!=null)try con.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();public static void close(Connection con, PreparedStatement prest) / TODO Auto-generated method stubif(prest!=null)try prest.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();if(con!=null)try con.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();public static void close(Connection con,PreparedStatement prest,ResultSet rs)try if(rs!=null)rs.close();if(prest!=null)prest.close();if(con!=null)con.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();public static void Close(PreparedStatement prest, Connection con) / TODO Auto-generated method stubif(prest!=null)try prest.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();if(con!=null)try con.close(); catch (SQLException e) / TODO Auto-generated catch blocke.printStackTrace();/类AddTeapublic void mouseClicked(MouseEvent e) /确定添加String id=textid.getText().toString();String name=textname.getText().toString();String teacher=textteacher.getText().toString();String title=texttitle.getText().toString();String date=textdate.getText().toString();String type=texttype.getSelectedItem().toString();String money=textmoney.getText().toString();String time=texttime.getSelectedItem().toString(); Teacher teacher1=new Teacher(id,name,teacher,title,date,type,money,time); TeacherDao teacherdao=new TeacherDao(); /addtea int count=teacherdao.addTea(teacher1); if(count=1) JOptionPane.showMessageDialog(null, "新增信息成功"); else JOptionPane.showMessageDialog(null, "新增信息失败"); /类Delectpublic void mouseClicked(MouseEvent arg0) /删除String id=textid.getText().toString();String name=textname.getText().toString();String teacher=textteacher.getText().toString();String title=texttitle.getText().toString(); String date=textdate.getText().toString();String type=(String) texttype.getSelectedItem();String money=textmoney.getText().toString();String time=(String) texttime.getSelectedItem(); Teacher teacher1=new Teacher(id,name,teacher,title,date,type,money,time); int count=TeacherDao.Delect(teacher1); if(count=1) JOptionPane.showMessageDialog(null, "删除成功"); else JOptionPane.showMessageDialog(null, "删除失败"); /类Loginpublic class Login extends JFrame public Login() public void mouseClicked(MouseEvent e) /实现登录操作/得到用户名Main frame=new Main();frame.setVisible(true);String u=username.getText().toString();String p=password.getText().toString();Users user=new Users(u,p);UsersDao userdao=new UsersDao();boolean flag= userdao.checkUser(user);if(flag)JOptionPane.showMessageDialog(null, "登录成功");else JOptionPane.showMessageDialog(null, "登录失败");final JButton regist = new JButton("u6CE8u518C");regist.addMouseListener(new MouseAdapter() Overridepublic void mouseClicked(MouseEvent e) Regist frame=new Regist();frame.setVisible(true); );/类Mainpublic class Main extends JFrame types.addMouseListener(new MouseAdapter() Overridepublic void mouseClicked(MouseEvent e) String cate=comboBox1.getSelectedItem().toString();TeacherDao dao = new TeacherDao();Vector vt=dao.findkind(cate);Vector<String> v=new Vector<String>();v.add("id");v.add("name");v.add("teacher");v.add("title");v.add("date");v.add("type");v.add("money");v.add("time");/Vector v_tea=teacherdao.getAllTea1(type);DefaultTableModel model=new DefaultTableModel(vt,v);table.setModel(model);xiugai.addMouseListener(new MouseAdapter() Overridepublic void mouseClicked(MouseEvent e) /点击修改,需要传值到id号;if(textid.getText().equals("")JOptionPane.showMessageDialog(null, "请输入要修改的id号:");String id=textid.getText();Update frame=new Update();frame.setVisible(true);)/类Registpublic class Regist extends JFrame public Regist() JButton button = new JButton("u6CE8u518C");button.addMouseListener(new MouseAdapter() Overridepublic void mouseClicked(MouseEvent e) /得到页面所输入信息String username=txt_name.getText();String password=txt_word.getText();Users use=new Users(username,password);UsersDao usersdao=new UsersDao();int count=usersdao.addUser(use);if(count=1)JOptionPane.showMessageDialog(null, "注册成功"); elseJOptionPane.showMessageDialog(null, "注册失败"); );/类Updatepublic class Update extends JFrame public static void main(String args) EventQueue.invokeLater(new Runnable() public void run() try Update frame = new Update();frame.setVisible(true); catch (Exception e) e.printStackTrace(););public Update() JButton regist2 = new JButton("u4FEEu6539");regist2.addMouseListener(new MouseAdapter() Overridepublic void mouseClicked(MouseEvent e) /修改信息