通达学院2017/2018 学年第 1 学期课程设计实验报告模块名称综合软件设计专业通信工程学生班级141301学生学号********学生姓名陈启朋指导教师王诚目录第一章在线考试系统 (1)1.1 实验目的 (1)1.2 实验内容 (1)1.3.1考试登录模块设计 (1)1.3.2管理员模块设计 (7)1.4 实验结果 (12)第二章学生成绩管理系统 (13)2.1 实验目的 (13)2.2 实验内容 (13)2.3 实验过程 (13)2.3.1学生成绩管理模块设计 (13)2.3.2 公共模块设计 (18)2.4 实验结果 (20)总结 (21)参考文献 (21)第一章在线考试系统1.1 实验目的通过本次软件设计,使学生掌握并能熟练运用Java和mysql语言编写程序,掌握面向对象的概念,采用C/S结构,设计数据库模型,能够了解和数据库连接的方法。
1.2 实验内容本次实验的内容是编辑生成试题库,随机生成本次考试试题,提供在先评分并保存结果;同时,管理员可以添加、修改、删除考题和考生用户。
1.3 实验过程1.3.1考试登录模块设计主要程序如下:package com.Exam.Index;import java.awt.Insets;import javax.swing.*;import javax.swing.GroupLayout; import youtStyle; import com.Exam.bean.*; 考试管理模块考生管理员开始考试查看考试规则修改密码进行查分添加用户修改考题设置考试参数删除用户修改用户删除考题添加考题用户查分import com.Exam.controller.ControllerFrame;import com.Exam.dao.*;public class MyLand extends javax.swing.JFrame {initComponents();}@SuppressWarnings("unchecked")private void initComponents() {jTextField3 = new javax.swing.JTextField();jTextField1 = new javax.swing.JTextField();jpanel = new MyJPanel();choicejLabel = new javax.swing.JLabel();userChoicejComboBox = new javax.swing.JComboBox();choicejLabel1 = new javax.swing.JLabel();UserNameTextField = new javax.swing.JTextField();choicejLabel2 = new javax.swing.JLabel();PassWordjTextField = new javax.swing.JPasswordField();enterButton = new javax.swing.JButton();enterButton.setMargin(new Insets(2, 2, 2, 2));resButtonjButton = new javax.swing.JButton();resButtonjButton.setMargin(new Insets(2, 2, 2, 2));jTextField3.setText("jTextField3");jTextField1.setText("jTextField1");setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);choicejLabel.setText("选择用户:");userChoicejComboBox.setModel(newjavax.swing.DefaultComboBoxModel(new String[] { "","考生", "管理员" }));setTitle("考试系统");choicejLabel1.setText("用户名:");UserNameTextField.setText("");choicejLabel2.setText(" 密码:");PassWordjTextField.setText("");enterButton.setText("登录");enterButton.addActionListener(new java.awt.event.ActionListener() {public void actionPerformed(java.awt.event.ActionEvent evt) {enterButtonActionPerformed(evt);}});resButtonjButton.setText("重置");resButtonjButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) {jButton2ActionPerformed(evt);}});javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());getContentPane().setLayout(layout);layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jpanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jpanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));javax.swing.GroupLayout jpanelLayout = new javax.swing.GroupLayout(jpanel);jpanelLayout.setHorizontalGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING).addGroup(jpanelLayout.createSequentialGroup().addGap(216, 216, 216).addGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(jpanelLayout.createSequentialGroup().addComponent(choicejLabel,GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE).addPreferredGap(ponentPlacement.RELATED).addComponent(userChoicejComboBox,GroupLayout.PREFERRED_SIZE, 120, GroupLayout.PREFERRED_SIZE)).addGroup(jpanelLayout.createSequentialGroup().addPreferredGap(ponentPlacement.RELATED .addGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(jpanelLayout.createSequentialGroup().addPreferredGap(ponentPlacement.RELATED).addComponent(choicejLabel2,GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE).addPreferredGap(ponentPlacement.RELATED).addComponent(PassWordjTextField, GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)).addGroup(jpanelLayout.createSequentialGroup().addComponent(choicejLabel1,GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE).addPreferredGap(ponentPlacement.RELATED).addComponent(UserNameTextField, GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE))))).addGap(82, 82, 82)).addGroup(jpanelLayout.createSequentialGroup().addContainerGap(256, Short.MAX_VALUE).addComponent(enterButton, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE).addPreferredGap(ponentPlacement.RELATED).addComponent(resButtonjButton).addGap(123, 123, 123)));jpanelLayout.setVerticalGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(jpanelLayout.createSequentialGroup().addGap(85, 85, 85).addGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(choicejLabel).addComponent(userChoicejComboBox,GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ponentPlacement.RELATED) .addGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(choicejLabel1).addComponent(UserNameTextField,GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ponentPlacement.RELATED).addGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(choicejLabel2).addComponent(PassWordjTextField,GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(18, 18, 18).addGroup(jpanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(resButtonjButton,GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE).addComponent(enterButton, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)).addContainerGap(71, Short.MAX_VALUE)));jpanel.setLayout(jpanelLayout);pack();}private void enterButtonActionPerformed(java.awt.event.ActionEvent evt) { if(userChoicejComboBox.getSelectedIndex()==0){JOptionPane.showMessageDialog(this, "没有确定路径的'用户类型'","信息对话框",JOptionPane.WARNING_MESSAGE);return;}if(UserNameTextField.getText().equals("")){JOptionPane.showMessageDialog(this, "用户名不能为空","密码不能为空",JOptionPane.WARNING_MESSAGE);return;}if(PassWordjTextField.getText().equals("")){JOptionPane.showMessageDialog(this,"密码不能为空","信息对话框",JOptionPane.WARNING_MESSAGE);return;}MyFindUserDao findUser = new MyFindUserDao();User user = new User();user.setUserName(UserNameTextField.getText());user.setPassWord(PassWordjTextField.getText());User users = findUser.getUser(user);if((users.getUserType() == 1 && !(userChoicejComboBox.getSelectedItem().equals("管理员")))){JOptionPane.showMessageDialog(this,"登录系统身份不符","信息对话框",JOptionPane.WARNING_MESSAGE);return;}if((users.getUserType() == 0) && !(userChoicejComboBox.getSelectedItem().equals("考生"))){JOptionPane.showMessageDialog(this,"登录系统身份不符","信息对话框",JOptionPane.WARNING_MESSAGE);return;}if((users.getId()!= 0 )&&(users.getUserType()==0)){int id = users.getId();java.io.File file = new java.io.File("save.txt");try {if(file.exists()){file.delete();}file.createNewFile();java.io.FileOutputStream out = new java.io.FileOutputStream(file);byte buy[] = (""+id).getBytes();out.write(buy);out.close();} catch (Exception e) {e.printStackTrace();}InsertUserDao insertUserDao = new InsertUserDao();insertUserDao.setUserHaveIn(users);StudentExam studentExam = new StudentExam();studentExam.setVisible(true);studentExam.setBounds(200, 200, 400, 300);studentExam.setTitle("考试系统");this.dispose();}if((users.getId()!=0)&&(users.getUserType()==1)){dispose();ControllerFrame controller = new ControllerFrame();controller.setVisible(true);controller.setBounds(100,100, 700, 500);}else if(users.getId() == 0){JOptionPane.showMessageDialog(this,"用户名或密码错误","信息对话框",JOptionPane.WARNING_MESSAGE);}}private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { UserNameTextField.setText("");PassWordjTextField.setText("");}public static void main(String[] args) {MyLand myLand = new MyLand();myLand.setVisible(true);}private javax.swing.JLabel choicejLabel;private javax.swing.JLabel choicejLabel1;private javax.swing.JLabel choicejLabel2;private javax.swing.JButton enterButton;private javax.swing.JButton resButtonjButton;private javax.swing.JComboBox userChoicejComboBox;private javax.swing.JPasswordField PassWordjTextField;private javax.swing.JTextField jTextField1;private javax.swing.JTextField UserNameTextField;private javax.swing.JTextField jTextField3;private MyJPanel jpanel;}1.3.2管理员模块设计添加用户模块设计主要程序如下:package com.Exam.controller;import javax.swing.JOptionPane;import com.Exam.bean.*;import com.Exam.dao.*;public class AddFrame extends javax.swing.JFrame {public AddFrame() {// 构造方法initComponents();// 调用初始化组件}@SuppressWarnings("unchecked")// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponentsprivate void initComponents() {jLabel1 = new javax.swing.JLabel();qTypejComboBox = new javax.swing.JComboBox();userNameLabel = new javax.swing.JLabel();jTextField1 = new javax.swing.JTextField();userPassWord = new javax.swing.JLabel();jPasswordField1 = new javax.swing.JPasswordField();okUserName = new javax.swing.JLabel();jPasswordField2 = new javax.swing.JPasswordField();addButton = new javax.swing.JButton();reset = new javax.swing.JButton();setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);addWindowListener(new java.awt.event.WindowAdapter() {// 为窗口设置监听 public void windowClosing(java.awt.event.WindowEvent evt) {formWindowClosing(evt);// 调用窗口监听的方法}});jLabel1.setText("用户类型:");qTypejComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--请选择用户身份--", "考生", "管理员" }));userNameLabel.setText("用户姓名:");jTextField1.setText("");userPassWord.setText("用户密码:");jPasswordField1.setText("");okUserName.setText("确认密码:");jPasswordField2.setText("");addButton.setText("添加");addButton.addActionListener(new java.awt.event.ActionListener() {public void actionPerformed(java.awt.event.ActionEvent evt) {addButtonActionPerformed(evt);}});reset.setText("重置");reset.addActionListener(new java.awt.event.ActionListener() {public void actionPerformed(java.awt.event.ActionEvent evt) {resetActionPerformed(evt);}});javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());getContentPane().setLayout(layout);layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(64, 64, 64).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Al ignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(okUserName).addPreferredGap(ponentPlace ment.RELATED).addComponent(jPasswordField2, 0, 0, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addComponent(userPassWord).addPreferredGap(ponentPlace ment.RELATED).addComponent(jPasswordField1, 0, 0, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addComponent(userNameLabel).addPreferredGap(ponentPlacement.RELATED).addComponent(jTextField1,javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)).addGroup(layout.createSequentialGroup().addComponent(jLabel1).addPreferredGap(ponentPlace ment.RELATED).addComponent(qTypejComboBox,javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))).addGap(74, 74, 74)).addGroup(layout.createSequentialGroup().addGap(115, 115, 115).addComponent(addButton).addGap(31, 31, 31).addComponent(reset).addContainerGap(107, Short.MAX_VALUE)));layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(39, 39, 39).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Al ignment.BASELINE).addComponent(jLabel1).addComponent(qTypejComboBox,javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(18, 18, 18).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Al ignment.BASELINE).addComponent(userNameLabel).addComponent(jTextField1,javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(18, 18, 18).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Al ignment.BASELINE).addComponent(userPassWord).addComponent(jPasswordField1,javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(18, 18, 18).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(okUserName).addComponent(jPasswordField2,javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(18, 18, 18).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Al ignment.BASELINE).addComponent(reset).addComponent(addButton)).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,Short.MAX_VALUE)));pack();}private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { String strQtype = qTypejComboBox.getSelectedItem().toString();// 获得前台选择的下拉列表内容if(jTextField1.getText().equals("")){JOptionPane.showMessageDialog(this, "请输入用户姓名","信息对话框",JOptionPane.WARNING_MESSAGE);// this表示此窗口return;}if(!jPasswordField1.getText().equals(jPasswordField2.getText())){ JOptionPane.showMessageDialog(this,"两次输入的密码不一致", "信息对话框",JOptionPane.WARNING_MESSAGE);return;}User user = new User();if(strQtype.equals("--请选择用户身份--")){JOptionPane.showMessageDialog(this,"请选择用户身份","信息对话框",JOptionPane.WARNING_MESSAGE);return;}if(strQtype.equals("考生")){user.setUserType(0);}if(strQtype.equals("管理员")){user.setUserType(1);}MyFindUserDao findUser = new MyFindUserDao();java.util.List list = findUser.findUser();for(int i = 0;i<list.size();i++){User users = (User)list.get(i);if(users.getUserName().equals(jTextField1.getText())){System.out.println("USERNAME "+users.getUserName());JOptionPane.showMessageDialog(this,"该用户名已存在" ,"信息对话框",JOptionPane.WARNING_MESSAGE);return;}}int i = findUser.getUserID();user.setUserName(jTextField1.getText());MyMD5 myMD5 = new MyMD5();user.setId(i+1);System.out.println("list "+list.size()+1);user.setPassWord(myMD5.createPassWord(jPasswordField1.getText()));InsertUserDao insertUser = new InsertUserDao();insertUser.setUserInfoToDBbean(user);JOptionPane.showMessageDialog(this,"用户添加" ,"信息对话框",JOptionPane.WARNING_MESSAGE);}private void resetActionPerformed(java.awt.event.ActionEvent evt) {// 重置的监听方法jTextField1.setText("");jPasswordField1.setText("");jPasswordField2.setText("");qTypejComboBox.setSelectedIndex(0);}private void formWindowClosing(java.awt.event.WindowEvent evt) {// 关闭窗体的监听方法dispose();ControllerFrame controll = new ControllerFrame();controll.setVisible(true);}public static void main(String args[]) {java.awt.EventQueue.invokeLater(new Runnable() {public void run() {new AddFrame().setVisible(true);}});}// Variables declaration - do not modify//GEN-BEGIN:variablesprivate javax.swing.JButton addButton;private javax.swing.JComboBox qTypejComboBox;private javax.swing.JLabel jLabel1;private javax.swing.JPasswordField jPasswordField1;private javax.swing.JPasswordField jPasswordField2;private javax.swing.JTextField jTextField1;private javax.swing.JLabel okUserName;private javax.swing.JButton reset;private javax.swing.JLabel userNameLabel;private javax.swing.JLabel userPassWord;// End of variables declaration//GEN-END:variables}1.4 实验结果本程序实现了一个实用的考试管理系统,该系统可以通过两种身份进入系统,分别为管理员和考生身份,管理员登录系统后,可以添加、修改和删除考生和试题,学生登录系统后,直接进入考试界面,进行考试。