1、java课程设计报告学生信息管理系统05152讲解Java网络编程实践课程设计说明书课程名称:JAVA网络编程课程设计题目:基于CS学生信息管理系统姓名: 赵 淳学号: 201105152班级:信息与计算科学1101班指导教师: 王小刚兰州交通大学软件科学与工程系二一三 年 十二 月 二十六 日一、课程设计目的1.通过JAVA课程设计,使学生能够将学到的面向对象的设计思想运用在具体的工作和学习中,加深对类和对象的理解,要求学生对生活中许多具体的事物抽象出类。2、通过这次课程设计掌握JAVA的编程思想,为后续课程打下基础。3、培养我实际操作能力和实践能力,为以后的工作打下坚实的基础。课程设计的要
2、求 利用学到的编程知识和编程技巧,要求学生:1、对系统进行功能模块分析、控制模块分析正确2、系统设计要能完成题目所要求的功能。3、编程简练,可用,尽可能的使系统的功能更加完善和全面4、使用说明书、流程图要清楚。二、解题思路1、课程设计的题目及简介有新生来报到,要逐个录入其信息,如:学生姓名,性别,出生日期,国籍。要求设计链表类来实现,并统计学生人数。文本界面为:1. 添加学生信息2. 删除学生信息3. 查询学生信息4. 修改学生信息5. 学生信息保存6. 退出2、设计说明总体结构我们采取模块化方式进行程序设计,要求程序的功能设计、数据结构设计及整体结构设计合理。也可根据自己对题目的理解增加新的
3、功能模块。系统以菜单界面方式(至少采用文本菜单界面,如能采用图形菜单界面更好)工作,运行界面友好,演示程序以用户和计算机的对话方式进行看题目要求,每一条记录包括一个学生的姓名、性别、出生日期、国籍。同时,应具备以下功能:1、删除功能:对指定学生的信息进行删除。2、修改功能:对指定学生的信息进行修改。3、查询功能:选择某种方式并输入该信息查询符合条件的学生信息。6、添加功能:添加新增学生信息。7、退出主菜单。三、 分析和设计 各功能模块的实现流程图:1增加学生信息判断*学生是否存在,若存在则错误,不存在则添加。具体流程如下图所示:流程图 2删除学生信息 删除学生的信息则必须对链表结点进行删除意味
4、着将某个要删除结点前后的连续打断,去掉该结点,使前后指针变量重新连接,完成链表结点的删除任务 流程图 3、查询学生信息按学生的学号进行查询 流程图: 总功能模块图:四、主要源代码import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;/主函数、主要类public class JCTX public static void main(String args) new Frm_Main(); / 实现类class Frm_Main implements ActionListener / thr
5、ows IOException public JFrame frame; public Container c; public JMenuBar menuBar; public JMenu mainMenu1; public JMenu mainMenu2; public JMenu mainMenu3; public JMenuItem subMenu1 = new JMenuItem5; public JMenuItem subMenu2 = new JMenuItem7; public JMenuItem subMenu3 = new JMenuItem2; JButton toolBa
6、rButton = new JButton8; public JToolBar toolBar; String strTip = 查询您要找的学生记录., 添加学生记录., 删除已有的学生记录, 修改学生记录., 使您修改的学生记录生效., 使 您添加的学生记录生效., 确认删除当前记录., 退出本系统:) ; String id = new String(); String name = new String(); String sex = new String(); String birthday = new String(); String address = new String();
7、 String birth = new String(); Connection conn; ResultSet rs; Statement st; PreparedStatement pst; public JLabel idL = new JLabel(学号:); public JLabel nameL = new JLabel(姓名:); public JLabel sexL = new JLabel(性别:); public JLabel jlbirth = new JLabel(出生年月:); public JLabel jladdr = new JLabel(籍贯:); publi
8、c JTextField idT = new JTextField(); public JTextField nameT = new JTextField(); public JTextField sexT = new JTextField(); public JTextField jtbirth = new JTextField(); public JTextField jtaddr = new JTextField(); public Frm_Main() frame = new JFrame(学生信息管理系统); c = frame.getContentPane(); c.setLayo
9、ut(null); menuBar = new JMenuBar(); toolBar = new JToolBar(); toolBar.setFloatable(false); frame.setJMenuBar(menuBar); frame.setResizable(false); mainMenu1 = new JMenu(管理); String str1 = 添加用户, 删除用户, 查询用户, , 退出 ; for (int i = 0; i 5; i+) if (i = 3) mainMenu1.addSeparator(); else subMenu1i = new JMenu
10、Item(str1i); subMenu1i.addActionListener(this); mainMenu1.add(subMenu1i); menuBar.add(mainMenu1); mainMenu2 = new JMenu(维护学生信息); String str2 = 查询记录, 添加记录, 删除记录, 修改记录, 提交修改, 提交添加, 确认删除 ; for (int i = 0; i 7; i+) subMenu2i = new JMenuItem(str2i); subMenu2i.addActionListener(this); mainMenu2.add(subMen
11、u2i); menuBar.add(mainMenu2); mainMenu3 = new JMenu(帮助); String str3 = 帮助., 关于. ; for (int i = 0; i 2; i+) subMenu3i = new JMenuItem(str3i); subMenu3i.addActionListener(this); mainMenu3.add(subMenu3i); menuBar.add(mainMenu3); String strToolBar = 查询, 添加, 删除, 修改, 提交修改, 提交添加, 确认删除 ; for (int i = 0; i 7
12、; i+) toolBarButtoni = new JButton(strToolBari); toolBarButtoni.setToolTipText(strTipi); toolBarButtoni.addActionListener(this); toolBar.add(toolBarButtoni); toolBar.setLocation(0, 0); toolBar.setSize(400, 30); c.add(toolBar); idL.setLocation(35, 40); idL.setSize(40, 20); / idL.setFont(new Font(宋体,F
13、ont.BOLD,12); c.add(idL); idT.setLocation(90, 40); idT.setSize(200, 20); / idT.setEnabled(false); c.add(idT); nameL.setLocation(35, 70); nameL.setSize(40, 20); c.add(nameL); nameT.setLocation(90, 70); nameT.setSize(200, 20); c.add(nameT); sexL.setLocation(35, 100); sexL.setSize(40, 20); c.add(sexL);
14、 sexT.setLocation(90, 100); sexT.setSize(200, 20); c.add(sexT); jlbirth.setLocation(35, 160); jlbirth.setSize(40, 20); c.add(jlbirth); jtbirth.setLocation(90, 160); jtbirth.setSize(200, 20); c.add(jtbirth); jladdr.setLocation(35, 190); jladdr.setSize(40, 20); c.add(jladdr); jtaddr.setLocation(90, 19
15、0); jtaddr.setSize(200, 20); c.add(jtaddr); JLabel information = new JLabel(); information.setFont(new Font(宋体, Font.BOLD, 35); information.setSize(380, 110); information.setLocation(10, 210); c.add(information); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); frame.se
16、tLocation(200, 200); frame.setVisible(true); conDB(); / 以上是设置数据库面版、框架 / 以下是连接数据库 public Connection conDB() Connection con = null; try Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver); catch (ClassNotFoundException e) try con = DriverManager.getConnection( jdbc:sqlserver:/127.0.0.1:1433;da
17、tabaseName=mysql, sa, 111); catch (SQLException e) JOptionPane.showMessageDialog(null, 数据库连接失败); return con; / 以下是关闭数据库 public void closeDB() try pst.close(); conn.close(); catch (SQLException e) JOptionPane.showMessageDialog(null, 数据库关闭失败!); / 以下是针对数据库的各种操作 public void actionPerformed(ActionEvent e
18、) conn=conDB(); if (e.getSource() = subMenu31 | e.getSource() = toolBarButton7) JOptionPane.showMessageDialog(null, ); if (e.getSource() = subMenu10 | e.getSource() = subMenu11 | e.getSource() = subMenu12) JOptionPane.showMessageDialog(null, ); / 查找功能的实现 if (e.getSource() = subMenu20 | e.getSource()
19、 = toolBarButton0) String idid = JOptionPane.showInputDialog(请输入要查找的学生学号); if (idid.trim() != ) /String strSQL = select * from student where id = + idid+ ; String strSQL = select * from student where id =? ; try pst=conn.prepareStatement(strSQL); pst.setString(1, idid); rs=pst.executeQuery(); /*st=c
20、onn.createStatement(); rs = st.executeQuery(strSQL);*/ int count = 0; while (rs.next() id = rs.getString(id); name = rs.getString(name); address = rs.getString(address); sex = rs.getString(sex); birth=rs.getString(birthday); count+; if (count = 0) JOptionPane.showMessageDialog(null, 对不起,没有您要查找的学生!);
21、 else idT.setText(id); nameT.setText(name); sexT.setText(sex); jtaddr.setText(address); jtbirth.setText(birth); catch (Exception ex) JOptionPane.showMessageDialog(null, 抱歉,程序出现异常!); if (e.getSource() = subMenu14) closeDB(); System.exit(0); if (e.getSource() = subMenu21 | e.getSource() = toolBarButto
22、n1) JOptionPane.showMessageDialog(null, 请输入要添加的学生信息); idT.setEnabled(true); idT.setText(); nameT.setText(); sexT.setText(); jtaddr.setText(); jtbirth.setText(); if (e.getSource() = toolBarButton5 | e.getSource() = subMenu25) if (idT.getText().trim().equals() | (nameT.getText().trim().equals() | (sex
23、T.getText().trim().equals() | (jtaddr.getText().trim().equals() | (jtbirth.getText().trim().equals() JOptionPane.showMessageDialog(null, 请输入信息再点击提交添加!); else id = idT.getText(); name = nameT.getText(); sex = sexT.getText(); birthday = jtaddr.getText(); address = jtbirth.getText(); String strSQL = in
24、sert into student values(?,?,?,?,?); try pst=conn.prepareStatement(strSQL); pst.setString(1, id); pst.setString(2, name); pst.setString(3, sex); pst.setString(4, address); pst.setString(5, birthday); pst.executeUpdate(); catch (SQLException e1) / TODO Auto-generated catch block /e1.printStackTrace()
25、; JOptionPane.showMessageDialog(null, 数据库中已经存在您要添加的学生的学号!); return; /*try pst.executeUpdate(strSQL); catch (Exception exx) JOptionPane.showMessageDialog(null, 数据库中已经存在您要添加的学生的学号!); * idT.setText(); nameT.setText(); sexT.setText(); * birthdayT.setText(); departmentT.setText(); return; */ JOptionPane.
26、showMessageDialog(null, 恭喜您,添加成功了!); if (e.getSource() = subMenu24 | e.getSource() = toolBarButton4) if (idT.getText().trim().equals() | (nameT.getText().trim().equals() | (sexT.getText().trim().equals() | (jtaddr.getText().trim().equals() | (jtbirth.getText().trim().equals() JOptionPane.showMessage
27、Dialog(null, 请输入信息再点击修改!); return; else id = idT.getText(); name = nameT.getText(); sex = sexT.getText(); birthday = jtaddr.getText(); address = jtbirth.getText(); String strSQL = update student set name=?,sex=?,address=?,birthday=? where id=?; try pst=conn.prepareStatement(strSQL); pst.setString(1, name); pst.setString(2, sex); pst.setString(3, address); pst.setString(4, birthday); pst.setString(5, id);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1