学生基本信息管理


项目简介

功能要求:
1)需要管理的学生信息有:学号、姓名、性别、出生日期、政治面貌、家庭住址、电话、宿舍号。
2)实现查询、增、删、改等功能。
数据存储:数据库或文件。
新增功能:找回密码、注册功能、作者介绍
运用了WindowBuilder插件,运用了Navicat for Mysql设计数据库及表。采用数据库技术。

功能架构图

在这里插入图片描述

一、登陆界面

部分主要代码:

package xues;

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.LayoutStyle.ComponentPlacement;

import lian.AdminLian;
import lian.StudentLian;

import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import model.Admin;
import model.Student;
import model.UserType;
import util.StringUtil;


import java.awt.SystemColor;

/**
 * @author dell
 */
public class Xue  {

	private JFrame frame;
	@SuppressWarnings("rawtypes")
	private JComboBox userTypeComboBox= new JComboBox();
	private JTextField userNameTextField;
	private JTextField passwordTextField;
	private JButton enrollButton;
	private JButton retrievePasswordButton;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				try {
					Xue window = new Xue();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Xue() {
	
		frame = new JFrame();
		frame.getContentPane().setBackground(SystemColor.control);
		frame.setTitle("\u767B\u9646\u754C\u9762");
		frame.setBounds(100, 100, 664, 460);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JLabel lblNewLabel = new JLabel("\u5B66\u751F\u4FE1\u606F\u7BA1\u7406\u7CFB\u7EDF");
		lblNewLabel.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u5B66\u6821_\u5B66\u751F.png"));
		lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
		
		JLabel lblNewLabel1 = new JLabel("");
		
		JLabel lblNewLabel2 = new JLabel("\u7528\u6237\u540D\uFF1A");
		lblNewLabel2.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u7528\u6237.png"));
		lblNewLabel2.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		
		userNameTextField = new JTextField();
		userNameTextField.setColumns(10);
		
		JLabel lblNewLabel3 = new JLabel("\u5BC6 \u7801\uFF1A");
		lblNewLabel3.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u5BC6\u7801.png"));
		lblNewLabel3.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		
		passwordTextField = new JTextField();
		passwordTextField.setColumns(10);
		
		JLabel lblNewLabel4 = new JLabel("\u7528\u6237\u7C7B\u578B\uFF1A");
		lblNewLabel4.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u7528\u6237\u7C7B\u578B_\u753B\u677F 1.png"));
		lblNewLabel4.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		
		userTypeComboBox.setModel(new DefaultComboBoxModel(new UserType[] {UserType.ADMIN, UserType.STUDENT}));
		//将用户类型放在枚举类中,不存放在数据库中。
		userTypeComboBox.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		JButton loginButton = new JButton("\u767B\u5F55");
		loginButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent be) {
				loginAction(be);
			}
		});
		loginButton.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u767B\u5F55.png"));
		loginButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		 enrollButton = new JButton("\u6CE8\u518C");
		enrollButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent he) {
				zhuCe(he);
			}
		});
		enrollButton.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u6CE8\u518C.png"));
		enrollButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
	
		 retrievePasswordButton = new JButton("\u627E\u56DE\u5BC6\u7801");
		retrievePasswordButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent se) {
				retrievePassword(se);
			}
		});
		retrievePasswordButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(174)
									.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 301, GroupLayout.PREFERRED_SIZE))
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(143)
									.addComponent(lblNewLabel1, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE))
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(122)
									.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
										.addGroup(groupLayout.createSequentialGroup()
											.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
												.addComponent(lblNewLabel2)
												.addComponent(lblNewLabel3))
											.addGap(22)
											.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
												.addComponent(userNameTextField)
												.addComponent(passwordTextField, GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)))
										.addGroup(groupLayout.createSequentialGroup()
											.addComponent(lblNewLabel4)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(userTypeComboBox, 0, 233, Short.MAX_VALUE)))))
							.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(35)
							.addComponent(enrollButton, GroupLayout.PREFERRED_SIZE, 134, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED, 101, Short.MAX_VALUE)
							.addComponent(loginButton, GroupLayout.PREFERRED_SIZE, 132, GroupLayout.PREFERRED_SIZE)
							.addGap(91)))
					.addComponent(retrievePasswordButton, GroupLayout.PREFERRED_SIZE, 120, GroupLayout.PREFERRED_SIZE)
					.addGap(85))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(25)
					.addComponent(lblNewLabel)
					.addGap(45)
					.addComponent(lblNewLabel1)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel2)
						.addComponent(userNameTextField, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE))
					.addGap(39)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(passwordTextField, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNewLabel3))
					.addGap(27)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel4, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
						.addComponent(userTypeComboBox, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE))
					.addGap(42)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(enrollButton, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
						.addComponent(retrievePasswordButton, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
						.addComponent(loginButton))
					.addContainerGap(26, Short.MAX_VALUE))
		);
		
		frame.getContentPane().setLayout(groupLayout); 
		enrollButton.setEnabled(false);
		retrievePasswordButton.setEnabled(false);
	}

	protected void retrievePassword(ActionEvent se) {
		// TODO Auto-generated method stub
		frame.dispose();
		new RetrievePassword().setVisible(true);;
	}

	protected void zhuCe(ActionEvent he) {
		// TODO Auto-generated method stub
		frame.dispose();
		JOptionPane.showMessageDialog(null,"欢迎注册!");
		new ZhuCe().setVisible(true);
	}

	protected void loginAction(ActionEvent be) {
		// TODO Auto-generated method stub
		//获取用户类型的值,将Object强制转换为UserType
		UserType selectedItem = (UserType)userTypeComboBox.getSelectedItem();
		//获取用户输入的值
		String userName=userNameTextField.getText().toString();
		//获取密码的值
		String password=passwordTextField.getText().toString();
		if(StringUtil.isEmpty(userName)){
			JOptionPane.showMessageDialog(null, "用户名不能为空!");
			return;
		}//弹出窗口
			if(StringUtil.isEmpty(password)) {
				JOptionPane.showMessageDialog(null, "密码不能为空!");
				return;
			}//弹出窗口
		Admin admin = null;
		String s="管理员";
		String h="学生";
	if(s.equals(selectedItem.getName())) {
			//管理员登录
		//注册按钮
		enrollButton.setEnabled(true);
		//找回密码按钮
		retrievePasswordButton.setEnabled(true);
			AdminLian adminLian=new AdminLian();
			Admin adminTmp =new Admin();
			 adminTmp.setName(userName);
			 adminTmp.setPassword(password);
			admin=adminLian.login(adminTmp);
			adminLian.closeDao();
			if(admin==null) {
				JOptionPane.showMessageDialog(null, "用户名或密码错误!");
				return;}
			//将登陆页面隐藏掉
			frame.dispose();
			JOptionPane.showMessageDialog(null,"欢迎【"+selectedItem.getName()+"】:"+admin.getName()+"登录系统!");
			new MainFrame(selectedItem,admin).setVisible(true);
			}
		else if(h.equals(selectedItem.getName())){
			//学生登录
			Student student=null;
			StudentLian studentLian = new StudentLian();
			Student studentTmp = new Student();
			studentTmp.setName(userName);
			studentTmp.setPassword(password);
			student = studentLian.login(studentTmp);
			studentLian.closeDao();
			if(student==null) {
				JOptionPane.showMessageDialog(null, "用户名或密码错误!");
				return;
			}
			//将登陆页面隐藏掉
			frame.dispose();
			JOptionPane.showMessageDialog(null,"欢迎【"+selectedItem.getName()+"】:"+student.getName()+"登录系统!");
			new MainFrame(selectedItem,student).setVisible(true);
		}
		
	}
	
	public void setVisible(boolean b) {
		// TODO Auto-generated method stub
		frame.setVisible(true);
	}

	
}

与数据库进行比对

package lian;
import model.Admin;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
 * @author 
 */
public class AdminLian extends BaseLian {
	
//管理员登录
	/**
	 * @author dell
	 */
		public Admin login(Admin admin){
			/**使用sql语句提取数据库中相应的name,password,"?"单位符*/
			String sql = "select * from s_admin where name=? and password=?"; 
			Admin adminRst = null;
			try {/**把sql语句传给数据库操作对象*/
				PreparedStatement prst = con.prepareStatement(sql); 
				prst.setString(1, admin.getName());
				prst.setString(2, admin.getPassword());
				/**得到值*/
				ResultSet executeQuery = prst.executeQuery();
				if(executeQuery.next()){
					adminRst = new Admin();
					adminRst.setId(executeQuery.getInt("id"));
					adminRst.setName(executeQuery.getString("name"));
					adminRst.setPassword(executeQuery.getString("password"));
				
				}/**看是否有值,若有则用户密码正确*/
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return adminRst;
		}
		
	}
	//StudentLian.java
	public Student login(Student student){
	String sql = "select * from s_student where name=? and password=?";
	Student studentRst = null;
	try {
		//把sql语句传给数据库操作对象
		PreparedStatement prst = con.prepareStatement(sql);
		prst.setString(1, student.getName());
		prst.setString(2, student.getPassword());
		ResultSet executeQuery = prst.executeQuery();
		if(executeQuery.next()){
			studentRst = new Student();
			studentRst.setId(executeQuery.getInt("id"));
			studentRst.setStudentNumber(executeQuery.getString("studentNumber"));
			studentRst.setName(executeQuery.getString("name"));
			studentRst.setGender(executeQuery.getString("gender"));
			studentRst.setGender(executeQuery.getString("birth"));
			studentRst.setGender(executeQuery.getString("political"));
			studentRst.setGender(executeQuery.getString("homeAddress"));
			studentRst.setGender(executeQuery.getString("phone"));
			studentRst.setGender(executeQuery.getString("dormId"));
			studentRst.setPassword(executeQuery.getString("password"));
		}
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return studentRst;
}

二、注册界面

代码如下:

package xues;


import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import lian.ZhuLian;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JTextField;


import model.Zhuce;
import util.StringUtil;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
 * @author dell
 */
public class ZhuCe extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField userNameTextField;
	private JTextField passwordTextField;
	private JTextField confirmPasswordTextField;
	private JTextField questionTextField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				try {
					ZhuCe frame = new ZhuCe();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ZhuCe() {
		setTitle("\u6CE8\u518C\u9875\u9762");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 620, 484);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel lblNewLabel = new JLabel("\u5B66\u751F\u4FE1\u606F\u7BA1\u7406\u7CFB\u7EDF\u7528\u6237\u6CE8\u518C");
		lblNewLabel.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\305\u4FE1\u606F-\u5706\u6846.png"));
		lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 36));
		
		JLabel lblNewLabel1 = new JLabel("\u7528\u6237\u540D\uFF1A");
		lblNewLabel1.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u7528\u6237.png"));
		lblNewLabel1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		
		userNameTextField = new JTextField();
		userNameTextField.setColumns(10);
		
		JLabel lblNewLabel2 = new JLabel("\u5BC6\u7801\uFF1A");
		lblNewLabel2.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u5BC6\u7801.png"));
		lblNewLabel2.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		
		passwordTextField = new JTextField();
		passwordTextField.setColumns(10);
		
		JButton zhuCeButton = new JButton("\u6CE8\u518C");
		zhuCeButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent be) {
				zhu(be);
			}
		});
		zhuCeButton.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u6CE8\u518C.png"));
		zhuCeButton.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		
		JLabel lblNewLabel3 = new JLabel("\u786E\u8BA4\u5BC6\u7801\uFF1A");
		lblNewLabel3.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u786E\u8BA4\u5BC6\u7801.png"));
		lblNewLabel3.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		
		confirmPasswordTextField = new JTextField();
		confirmPasswordTextField.setColumns(10);
		
		JButton btnNewButton = new JButton("\u8FD4\u56DE\u767B\u5F55");
		btnNewButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				login(e);
			}
		});
		btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		JLabel lblNewLabel4 = new JLabel("\u5BC6\u4FDD\u95EE\u9898\uFF1A\u4F60\u6700\u559C\u6B22\uFF1F");
		lblNewLabel4.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u5BC6\u4FDD\u95EE\u9898.png"));
		lblNewLabel4.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		
		questionTextField = new JTextField();
		questionTextField.setColumns(10);
		GroupLayout glContentPane = new GroupLayout(contentPane);
		glContentPane.setHorizontalGroup(
				glContentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(glContentPane.createSequentialGroup()
					.addGroup(glContentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(glContentPane.createSequentialGroup()
							.addGap(10)
							.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 559, GroupLayout.PREFERRED_SIZE))
						.addGroup(glContentPane.createSequentialGroup()
							.addGap(58)
							.addComponent(lblNewLabel1)
							.addGap(28)
							.addComponent(userNameTextField, GroupLayout.PREFERRED_SIZE, 284, GroupLayout.PREFERRED_SIZE))
						.addGroup(glContentPane.createSequentialGroup()
							.addGap(58)
							.addComponent(lblNewLabel2, GroupLayout.PREFERRED_SIZE, 106, GroupLayout.PREFERRED_SIZE)
							.addGap(32)
							.addComponent(passwordTextField, GroupLayout.PREFERRED_SIZE, 284, GroupLayout.PREFERRED_SIZE))
						.addGroup(glContentPane.createSequentialGroup()
							.addGap(206)
							.addComponent(zhuCeButton, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE)
							.addGap(59)
							.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE))
						.addGroup(glContentPane.createSequentialGroup()
							.addGap(58)
							.addGroup(glContentPane.createParallelGroup(Alignment.LEADING, false)
								.addGroup(glContentPane.createSequentialGroup()
									.addComponent(lblNewLabel4, GroupLayout.PREFERRED_SIZE, 210, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(questionTextField, GroupLayout.PREFERRED_SIZE, 208, GroupLayout.PREFERRED_SIZE))
								.addGroup(glContentPane.createSequentialGroup()
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(lblNewLabel3)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(confirmPasswordTextField)))))
					.addContainerGap(43, Short.MAX_VALUE))
		);
		glContentPane.setVerticalGroup(
				glContentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(glContentPane.createSequentialGroup()
					.addComponent(lblNewLabel)
					.addGap(13)
					.addGroup(glContentPane.createParallelGroup(Alignment.LEADING)
						.addComponent(lblNewLabel1)
						.addGroup(glContentPane.createSequentialGroup()
							.addGap(6)
							.addComponent(userNameTextField, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)))
					.addGap(44)
					.addGroup(glContentPane.createParallelGroup(Alignment.LEADING)
						.addComponent(lblNewLabel2)
						.addGroup(glContentPane.createSequentialGroup()
							.addGap(6)
							.addComponent(passwordTextField, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE)))
					.addGap(40)
					.addGroup(glContentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel3)
						.addComponent(confirmPasswordTextField, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE))
					.addGap(32)
					.addGroup(glContentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel4)
						.addComponent(questionTextField, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
					.addGap(45)
					.addGroup(glContentPane.createParallelGroup(Alignment.TRAILING)
						.addComponent(zhuCeButton, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnNewButton))
					.addContainerGap())
		);
		contentPane.setLayout(glContentPane);
	}

	protected void login(ActionEvent e) {
		// TODO Auto-generated method stub
		this.dispose();
		new Xue().setVisible(true);}
	protected void zhu (ActionEvent me) {
		// TODO Auto-generated method stub
		//获取用户输入的值
		String userName=userNameTextField.getText().toString();
		//获取密码的值
		String password=passwordTextField.getText().toString();
		//获取确认密码的值
		String confirmPassword=confirmPasswordTextField.getText().toString();
		//获得回答的值
		String question=questionTextField.getText().toString();
		if(StringUtil.isEmpty(userName)){
			JOptionPane.showMessageDialog(this,"用户名不能为空!");
			return;
		}//弹出窗口
			if(StringUtil.isEmpty(password)) {
				JOptionPane.showMessageDialog(this,"密码不能为空!");
				return;
			}//弹出窗口
			if(StringUtil.isEmpty(confirmPassword)){
				JOptionPane.showMessageDialog(this,"确认密码不能为空!");
				return;
			}//弹出窗口
			if(StringUtil.isEmpty(question)){
				JOptionPane.showMessageDialog(this,"回答不能为空!");
				return;
			}//弹出窗口
			if(!confirmPassword.equals(password) ) {
				JOptionPane.showMessageDialog(this,"密码不对,请重新输入!");
			}//判断密码与确认密码是否一致
			if(confirmPassword.equals(password)) {
			Zhuce zhuce=new Zhuce();
			zhuce.setName(userName);
			zhuce.setPassword(password);
			zhuce.setConfirmPassword(confirmPassword);
			zhuce.setQuestion(question);
			ZhuLian zhulian=new ZhuLian();
			if(zhulian.add(zhuce)) {
				JOptionPane.showMessageDialog(this, "注册成功!");
				resetValue(me);
				return;
				
			}else {
				JOptionPane.showMessageDialog(this, "注册失败!");
				
			}	
			}
			}
			 
			
			
	private void resetValue(ActionEvent me) {
		// TODO Auto-generated method stub
		userNameTextField.setText("");
		passwordTextField.setText("");
		confirmPasswordTextField.setText("");
		questionTextField.setText("");
	}
}

三、找回密码界面

package xues;


import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import java.awt.Color;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import lian.MiBaoLian;
import model.Mibao;
import util.StringUtil;

import java.awt.SystemColor;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Vector;
import java.awt.event.ActionEvent;
/**
 * @author dell
 */
public class RetrievePassword extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField nameTextField;
	private JLabel lblNewLabel1;
	private JScrollPane scrollPane1;
	private JTable table;
	private JTextField questionTextField;
 private JButton btnNewButton =new JButton("\u786E\u5B9A");
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				try {
					RetrievePassword frame = new RetrievePassword();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public RetrievePassword() {
		setTitle("\u627E\u56DE\u5BC6\u7801\u754C\u9762");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 567, 401);
		contentPane = new JPanel();
		contentPane.setBackground(SystemColor.control);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel lblNewLabel = new JLabel("\u7528\u6237\u540D\uFF1A");
		lblNewLabel.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u7528\u6237.png"));
		lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		
		nameTextField = new JTextField();
		nameTextField.setColumns(10);
		
		lblNewLabel1 = new JLabel("\u5BC6\u4FDD\u95EE\u9898\uFF1A\u4F60\u6700\u559C\u6B22\uFF1F");
		lblNewLabel1.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u5BC6\u4FDD\u95EE\u9898.png"));
		lblNewLabel1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		
		JScrollPane scrollPane = new JScrollPane();
		
		scrollPane1 = new JScrollPane();
		
		// btnNewButton = new JButton("\u786E\u5B9A");
		btnNewButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent ie) {
				que(ie);
			}
		});
		btnNewButton.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u786E\u5B9A.png"));
		btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		btnNewButton.setForeground(Color.BLACK);
		
		questionTextField = new JTextField();
		questionTextField.setColumns(10);
		
		JButton loginButton = new JButton("\u8FD4\u56DE\u767B\u5F55");
		loginButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		loginButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent xe) {
				login(xe);
			}
		});
		GroupLayout glContentPane = new GroupLayout(contentPane);
		glContentPane.setHorizontalGroup(
				glContentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(glContentPane.createSequentialGroup()
					.addGap(23)
					.addGroup(glContentPane.createParallelGroup(Alignment.TRAILING)
						.addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 405, GroupLayout.PREFERRED_SIZE)
						.addGroup(glContentPane.createSequentialGroup()
							.addGroup(glContentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(lblNewLabel1)
								.addComponent(lblNewLabel))
							.addGap(18)
							.addGroup(glContentPane.createParallelGroup(Alignment.LEADING, false)
								.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)
								.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(nameTextField, GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
								.addComponent(questionTextField))))
					.addContainerGap(100, Short.MAX_VALUE))
				.addGroup(glContentPane.createSequentialGroup()
					.addContainerGap(362, Short.MAX_VALUE)
					.addComponent(loginButton, GroupLayout.PREFERRED_SIZE, 106, GroupLayout.PREFERRED_SIZE)
					.addGap(60))
		);
		glContentPane.setVerticalGroup(
				glContentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(glContentPane.createSequentialGroup()
					.addGap(36)
					.addGroup(glContentPane.createParallelGroup(Alignment.TRAILING)
						.addComponent(nameTextField, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNewLabel))
					.addGap(30)
					.addGroup(glContentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel1)
						.addComponent(questionTextField, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
					.addComponent(btnNewButton)
					.addGap(18)
					.addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 104, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGap(13)
					.addComponent(loginButton))
		);
		
		table = new JTable();
		table.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		table.setForeground(Color.BLACK);
		table.setBackground(Color.WHITE);
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u5BC6\u7801"
			}
		));
		table.getColumnModel().getColumn(0).setPreferredWidth(35);
		table.getColumnModel().getColumn(0).setMinWidth(10);
		scrollPane1.setViewportView(table);
		contentPane.setLayout(glContentPane);
	}
	
	protected void login(ActionEvent xe) {
		// TODO Auto-generated method stub
		this.dispose();
		new Xue().setVisible(true);
	}

	Mibao mibao=null;
	protected void que(ActionEvent ie) {
		// TODO Auto-generated method stub
		String userName=nameTextField.getText().toString();
		String question=questionTextField.getText().toString();
		if(StringUtil.isEmpty(userName)){
			JOptionPane.showMessageDialog(null, "用户名不能为空!");
			return;
		}//弹出窗口
			if(StringUtil.isEmpty(question)) {
				JOptionPane.showMessageDialog(null, "回答不能为空!");
				return;
			}//弹出窗口
		MiBaoLian miLian=new MiBaoLian();
		Mibao mibaoTmp =new Mibao();
		mibaoTmp.setName(userName);
		mibaoTmp.setQuestion(question);

     mibao=miLian.que(mibaoTmp);
		miLian.closeDao();
		if(mibao!=null) {
			Mibao mi=new Mibao();
		mi.setName(nameTextField.getText().toString());
		mi.setQuestion(questionTextField.getText().toString());
		setTable(mi);}
		
		else {JOptionPane.showMessageDialog(null, "回答错误!");
		return;
		}
		
	}
	
public void setTable(Mibao mi) {
			  DefaultTableModel	dft =(DefaultTableModel) table.getModel();
			  //把列表先清空
			  dft.setRowCount(0);
			  MiBaoLian miLian=new MiBaoLian();
			 List<Mibao> miList= miLian.getMibaoList(mi);
			 for(Mibao s:miList) {
				 Vector<String> v=new Vector<String>(); 
				 v.add(s.getPassword());
				
				 dft.addRow(v);
			 }//遍历
			  miLian.closeDao();
			}
}

四、系统主界面

package xues;



import javax.swing.JFrame;

import java.awt.Desktop;

import model.Student;
import model.UserType;
import util.StringUtil;

import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.ImageIcon;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

import java.awt.event.ActionListener;
import java.util.List;
import java.util.Vector;
import java.awt.event.ActionEvent;


import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import lian.StudentLian;

import javax.swing.JRadioButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;


import javax.swing.JPasswordField;
import java.awt.Color;
/**
 * @author dell
 */
public class MainFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private UserType userType;
	
	private JTextField searchStudentNameTextField;
	private JTable studentListTable;
	private JTextField studentNameTextField;
	private JTextField studentNumberTextField;
	private JTextField birthDateTextField;
	private JTextField politicalStatusTextField;
	private JTextField homeAddressTextField;
	private JTextField phoneTextField;
	private JTextField dormIdTextField;
	private ButtonGroup genderButtonGroup;
	private JButton increaseButton;
	private JButton deleteButton;
	/**
	 * Launch the application.
	 * 防止变量userType、userObject为空,保证单一入口,必须从登陆页面进入
	 */

	private JRadioButton studentGenderManRadioButton;
	private JRadioButton studentGenderWomanRadioButton;
	private JPasswordField passwordField;
	/**
	 * Create the frame.
	 */
	public MainFrame(UserType userType,Object userObject) {
	//	setClosable(true);
		this.userType=userType;
		setTitle("\u5B66\u751F\u57FA\u672C\u4FE1\u606F\u7CFB\u7EDF\u4E3B\u754C\u9762");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 868, 717);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnNewMenu = new JMenu("\u7CFB\u7EDF\u8BBE\u7F6E");
		mnNewMenu.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u8BBE\u7F6E.png"));
		menuBar.add(mnNewMenu);
		
		JMenuItem mntmNewMenuItem = new JMenuItem("\u9000\u51FA");
		String m="确定退出吗?";
		mntmNewMenuItem.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent ge) {
				if(JOptionPane.showConfirmDialog(MainFrame.this,m)==JOptionPane.OK_OPTION) {
					System.exit(0);
				}
			}
		});
		mntmNewMenuItem.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u9000\u51FA.png"));
		mnNewMenu.add(mntmNewMenuItem);
		
		JMenuItem returnMenuItem = new JMenuItem("\u8FD4\u56DE\u767B\u5F55");
		returnMenuItem.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent te) {
				returnLogin(te);
			}
		});
		returnMenuItem.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u8FD4\u56DE.png"));
		mnNewMenu.add(returnMenuItem);
		
		JMenu zuoMenu = new JMenu("\u5E2E\u52A9");
		zuoMenu.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u5E2E\u52A9.png"));
		menuBar.add(zuoMenu);
		
		JMenuItem writerMenuItem = new JMenuItem("\u5173\u4E8E\u4F5C\u8005");
		writerMenuItem.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent ce) {
				aboutWriter(ce);
			}
		});
		writerMenuItem.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u7F8E\u5973.png"));
		zuoMenu.add(writerMenuItem);
		
		JScrollPane scrollPane = new JScrollPane();
		
		JLabel lblNewLabel = new JLabel("\u5B66\u751F\u59D3\u540D\uFF1A");
		lblNewLabel.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u5B66\u751F.png"));
		lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		searchStudentNameTextField = new JTextField();
		searchStudentNameTextField.setColumns(10);
		
		JButton searchButton = new JButton("\u67E5\u8BE2");
		searchButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent we) {
				searchStudent(we);
			}
		});
		searchButton.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u67E5\u8BE2 (1).png"));
		searchButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		JLabel newLabel = new JLabel("\u5B66\u751F\u59D3\u540D\uFF1A");
		newLabel.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u5B66\u751F.png"));
		newLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		studentNameTextField = new JTextField();
		studentNameTextField.setColumns(10);
		
		JLabel newLabel2 = new JLabel("\u5B66\u53F7\uFF1A");
		newLabel2.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u5B66\u53F7\u7BA1\u7406.png"));
		newLabel2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		studentNumberTextField = new JTextField();
		studentNumberTextField.setColumns(10);
		
		JLabel newLabel3 = new JLabel("\u6027\u522B\uFF1A");
		newLabel3.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u6027\u522B (1).png"));
		newLabel3.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		 studentGenderManRadioButton = new JRadioButton("\u7537");
		studentGenderManRadioButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		 studentGenderWomanRadioButton = new JRadioButton("\u5973");
		studentGenderWomanRadioButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		genderButtonGroup=new ButtonGroup();
		genderButtonGroup.add(studentGenderManRadioButton);
		genderButtonGroup.add(studentGenderWomanRadioButton);
		
		JLabel newLabel4 = new JLabel("\u51FA\u751F\u65E5\u671F\uFF1A");
		newLabel4.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u51FA\u751F\u65E5\u671F.png"));
		newLabel4.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		birthDateTextField = new JTextField();
		birthDateTextField.setColumns(10);
		
		JLabel newLabel5 = new JLabel("\u653F\u6CBB\u9762\u8C8C\uFF1A");
		newLabel5.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u653F\u6CBB.png"));
		newLabel5.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		politicalStatusTextField = new JTextField();
		politicalStatusTextField.setColumns(10);
		
		JLabel newLabel6 = new JLabel("\u5BB6\u5EAD\u4F4F\u5740\uFF1A");
		newLabel6.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u5BB6\u5EAD\u4F4F\u5740.png"));
		newLabel6.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		homeAddressTextField = new JTextField();
		homeAddressTextField.setColumns(10);
		
		JLabel newLabel7 = new JLabel("\u7535\u8BDD\uFF1A");
		newLabel7.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u7535\u8BDD.png"));
		newLabel7.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		phoneTextField = new JTextField();
		phoneTextField.setColumns(10);
		
		JLabel newLabel8 = new JLabel("\u5BBF\u820D\u53F7\uFF1A");
		newLabel8.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u5BBF\u820D.png"));
		newLabel8.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		dormIdTextField = new JTextField();
		dormIdTextField.setColumns(10);
		
		JButton reviseButton = new JButton("\u786E\u8BA4\u4FEE\u6539");
		reviseButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent le) {
				xiuGai(le);
			}
		});
		
		reviseButton.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\ok.png"));
		reviseButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		 increaseButton = new JButton("\u6DFB\u52A0");
		increaseButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent ve) {
				studentAdd(ve);
			}
		});
		increaseButton.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u6DFB\u52A0.png"));
		increaseButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		 deleteButton = new JButton("\u5220\u9664");
		deleteButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent ne) {
				deleteStudent(ne);
			}
		});
		deleteButton.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u5220\u9664.png"));
		deleteButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		JLabel newLabel9 = new JLabel("\u767B\u5F55\u5BC6\u7801\uFF1A");
		newLabel9.setIcon(new ImageIcon("C:\\Users\\dell\\Downloads\\\u5BC6\u7801.png"));
		newLabel9.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		
		passwordField = new JPasswordField();
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(106)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 634, GroupLayout.PREFERRED_SIZE)
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblNewLabel)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(searchStudentNameTextField, GroupLayout.PREFERRED_SIZE, 219, GroupLayout.PREFERRED_SIZE)
									.addGap(58)
									.addComponent(searchButton, GroupLayout.PREFERRED_SIZE, 110, GroupLayout.PREFERRED_SIZE))))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(45)
							.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
								.addGroup(groupLayout.createSequentialGroup()
									.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
										.addGroup(groupLayout.createSequentialGroup()
											.addComponent(newLabel2)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(studentNumberTextField, GroupLayout.PREFERRED_SIZE, 190, GroupLayout.PREFERRED_SIZE))
										.addGroup(groupLayout.createSequentialGroup()
											.addPreferredGap(ComponentPlacement.RELATED)
											.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
												.addGroup(groupLayout.createSequentialGroup()
													.addComponent(newLabel4)
													.addPreferredGap(ComponentPlacement.RELATED)
													.addComponent(birthDateTextField))
												.addGroup(groupLayout.createSequentialGroup()
													.addComponent(newLabel7)
													.addPreferredGap(ComponentPlacement.RELATED)
													.addComponent(phoneTextField, GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE)))))
									.addGap(18)
									.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
										.addGroup(groupLayout.createSequentialGroup()
											.addComponent(newLabel)
											.addPreferredGap(ComponentPlacement.UNRELATED)
											.addComponent(studentNameTextField, GroupLayout.PREFERRED_SIZE, 99, GroupLayout.PREFERRED_SIZE))
										.addGroup(groupLayout.createSequentialGroup()
											.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
												.addComponent(newLabel5)
												.addComponent(newLabel8))
											.addPreferredGap(ComponentPlacement.UNRELATED)
											.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
												.addComponent(dormIdTextField, 100, 100, 100)
												.addComponent(politicalStatusTextField, GroupLayout.PREFERRED_SIZE, 99, GroupLayout.PREFERRED_SIZE)))))
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(increaseButton, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)
									.addGap(113)
									.addComponent(deleteButton, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)
									.addGap(64)))
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(43)
									.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
										.addGroup(groupLayout.createSequentialGroup()
											.addComponent(newLabel3)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(studentGenderManRadioButton, GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(studentGenderWomanRadioButton, GroupLayout.PREFERRED_SIZE, 127, GroupLayout.PREFERRED_SIZE))
										.addGroup(groupLayout.createSequentialGroup()
											.addComponent(newLabel6, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(homeAddressTextField, GroupLayout.PREFERRED_SIZE, 132, GroupLayout.PREFERRED_SIZE))))
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(58)
									.addComponent(reviseButton, GroupLayout.PREFERRED_SIZE, 135, GroupLayout.PREFERRED_SIZE))
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(10)
									.addComponent(newLabel9)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, 117, GroupLayout.PREFERRED_SIZE)))))
					.addGap(10))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(30)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
						.addComponent(searchStudentNameTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(searchButton))
					.addGap(18)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 317, GroupLayout.PREFERRED_SIZE)
					.addGap(49)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
						.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
							.addComponent(newLabel3, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
							.addComponent(studentGenderManRadioButton)
							.addComponent(studentGenderWomanRadioButton))
						.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
							.addComponent(newLabel)
							.addComponent(studentNumberTextField, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
							.addComponent(newLabel2)
							.addComponent(studentNameTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addGap(19)
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(newLabel4)
						.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
							.addComponent(birthDateTextField, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
							.addComponent(newLabel5)
							.addComponent(politicalStatusTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addComponent(newLabel6)
							.addComponent(homeAddressTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addPreferredGap(ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(newLabel7, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
						.addComponent(phoneTextField, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE)
						.addComponent(newLabel8)
						.addComponent(dormIdTextField, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
						.addComponent(reviseButton, GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(increaseButton, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
						.addComponent(deleteButton, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
						.addComponent(newLabel9)
						.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE))
					.addGap(21))
		);
		
		studentListTable = new JTable();
		studentListTable.setBackground(Color.WHITE);
		studentListTable.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent de) {
				selectedTableRow(de);
			}
		});
		studentListTable.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u5E8F\u53F7", "\u5B66\u53F7", "\u5B66\u751F\u59D3\u540D", "\u6027\u522B", "\u51FA\u751F\u65E5\u671F", "\u653F\u6CBB\u9762\u8C8C", "\u5BB6\u5EAD\u4F4F\u5740", "\u7535\u8BDD", "\u5BBF\u820D\u53F7", "\u767B\u5F55\u5BC6\u7801"
			}
		) {
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;
			boolean[] columnEditables = new boolean[] {
				false, true, true, true, true, true, true, true, true, true
			};
			@Override
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		studentListTable.getColumnModel().getColumn(7).setPreferredWidth(58);
		scrollPane.setViewportView(studentListTable);
		getContentPane().setLayout(groupLayout);
		setTable(new Student());
		setAuthority();//调用方法,学生没有添加、删除的权限
	}


protected void returnLogin(ActionEvent te) {
		// TODO Auto-generated method stub
		this.dispose();
		new Xue().setVisible(true);
	}


protected void xiuGai(ActionEvent le) {
		// TODO Auto-generated method stub
	Student student=new Student();
	    String studentNumber=studentNumberTextField.getText().toString();
		String studentName=studentNameTextField.getText().toString();
		 if(studentGenderManRadioButton.isSelected()) {
			 student.setGender(studentGenderManRadioButton.getText().toString());
		 }
		 if(studentGenderWomanRadioButton.isSelected()) {
			 student.setGender(studentGenderWomanRadioButton.getText().toString());
		 }
		String birth= birthDateTextField.getText().toString();
		String political= politicalStatusTextField.getText().toString();
		String home= homeAddressTextField.getText().toString();
		String phone= phoneTextField.getText().toString();
		String dormId= dormIdTextField.getText().toString();
		@SuppressWarnings("deprecation")
		String password=new String(passwordField.getPassword());
		if(StringUtil.isEmpty(studentNumber)){
			JOptionPane.showMessageDialog(null, "请填写学号!");
			return;
		}//弹出窗口
		if(StringUtil.isEmpty(studentName)){
			JOptionPane.showMessageDialog(null, "请填写学生姓名!");
			return;
		}//弹出消息对话框
		if(StringUtil.isEmpty(birth)){
			JOptionPane.showMessageDialog(null, "请填写出生日期!");
			return;
		}//弹出窗口
		if(StringUtil.isEmpty(political)){
			JOptionPane.showMessageDialog(null, "请填写政治面貌!");
			return;
		}//弹出窗口
		if(StringUtil.isEmpty(home)){
			JOptionPane.showMessageDialog(null, "请填写家庭地址!");
			return;
		}//弹出窗口
		if(StringUtil.isEmpty(phone)){
			JOptionPane.showMessageDialog(null, "请填写电话!");
			return;
		}//弹出窗口
		if(StringUtil.isEmpty(dormId)){
			JOptionPane.showMessageDialog(null, "请填写宿舍号!");
			return;
		}//弹出窗口
		if(StringUtil.isEmpty(password)){
		JOptionPane.showMessageDialog(null, "请填写登录密码!");
			return;
		}//弹出窗口
		int row=studentListTable.getSelectedRow();
		if(row==-1) {
			JOptionPane.showMessageDialog(this, "请选中要修改的数据!");
			return;
		}//没选中
		student.setStudentNumber(studentNumber);
		student.setName(studentName);
		student.setBirth(birth);
		student.setPolitical(political);
		student.setHomeAddress(home);
		student.setPhone(phone);
		student.setDormId(dormId);
		student.setPassword(password);
		//传入id值
		student.setId(Integer.parseInt(studentListTable.getValueAt(row, 0).toString()));
		StudentLian studentLian=new StudentLian();
		if(	studentLian.update(student)) {
			JOptionPane.showMessageDialog(this, "修改成功!");
			resetValue(le);
		}else {
			JOptionPane.showMessageDialog(this, "修改失败!");
		}
		studentLian.closeDao();
		setTable(new Student());
	}


protected void selectedTableRow(MouseEvent de) {
		// TODO Auto-generated method stub
	String s="管理员";
		DefaultTableModel dft=(DefaultTableModel) studentListTable.getModel();
		studentNumberTextField.setText(dft.getValueAt(studentListTable.getSelectedRow(), 1).toString());
		studentNameTextField.setText(dft.getValueAt(studentListTable.getSelectedRow(),2).toString());
		String gender=dft.getValueAt(studentListTable.getSelectedRow(),3).toString();
		 genderButtonGroup.clearSelection();
		 if(gender.equals(studentGenderManRadioButton.getText())) {
			 studentGenderManRadioButton.setSelected(true);
		 }
		 if(gender.equals(studentGenderWomanRadioButton.getText())) {
			 studentGenderWomanRadioButton.setSelected(true);
		 }
		 birthDateTextField.setText(dft.getValueAt(studentListTable.getSelectedRow(), 4).toString());
		 politicalStatusTextField.setText(dft.getValueAt(studentListTable.getSelectedRow(), 5).toString());
		 homeAddressTextField.setText(dft.getValueAt(studentListTable.getSelectedRow(), 6).toString());
		 phoneTextField.setText(dft.getValueAt(studentListTable.getSelectedRow(), 7).toString());
		 dormIdTextField.setText(dft.getValueAt(studentListTable.getSelectedRow(), 8).toString());
		 int z=9;
		 if(s.equals(userType.getName())) { passwordField.setText(dft.getValueAt(studentListTable.getSelectedRow(), z).toString());
	}}


protected void deleteStudent(ActionEvent ne) {
		// TODO Auto-generated method stub
	String x="确定删除吗?";
	if(JOptionPane.showConfirmDialog(this,x)!=JOptionPane.OK_OPTION) {
	return;
	}
	int row=studentListTable.getSelectedRow();
		if(row==-1) {
			JOptionPane.showMessageDialog(this, "请选中要删除的数据!");
			return;
		}//没选中
		StudentLian studentLian=new StudentLian();
	if(	studentLian.delete(Integer.parseInt(studentListTable.getValueAt(row, 0).toString()))) {
		JOptionPane.showMessageDialog(this, "删除成功!");
		resetValue(ne);
	}else {
		JOptionPane.showMessageDialog(this, "删除失败!");
	}
	studentLian.closeDao();
	setTable(new Student());
	}

protected void searchStudent(ActionEvent we) {
		// TODO Auto-generated method stub
	Student student=new Student();
	student.setName(searchStudentNameTextField.getText().toString());
	setTable(student);
	}

public void setTable(Student student) {
  DefaultTableModel	dft =(DefaultTableModel) studentListTable.getModel();
  //把列表先清空
  dft.setRowCount(0);
  StudentLian studentLian=new StudentLian();
 List<Student> studentList= studentLian.getStudentList(student);
 String m="管理员";
 if(m.equals(userType.getName())) {
 for(Student s:studentList) {
	Vector<Comparable> v=new Vector<Comparable>();
	 v.add(s.getId());
	 v.add(s.getStudentNumber());
	 v.add(s.getName());
	 v.add(s.getGender());
	 v.add(s.getBirth());
	 v.add(s.getPolitical());
	 v.add(s.getHomeAddress());
	 v.add(s.getPhone());
	 v.add(s.getDormId());
	 v.add(s.getPassword());
	 //addRow()方法,这是添加行数据到表格中的方法
	 dft.addRow(v);
 }}//遍历
 String x="学生";
 if(x.equals(userType.getName())) {
	 for(Student s:studentList) {
		Vector<Comparable> v=new Vector<Comparable>();
		 v.add(s.getId());
		 v.add(s.getStudentNumber());
		 v.add(s.getName());
		 v.add(s.getGender());
		 v.add(s.getBirth());
		 v.add(s.getPolitical());
		 v.add(s.getHomeAddress());
		 v.add(s.getPhone());
		 v.add(s.getDormId());
		 dft.addRow(v);
	 }
 }
  studentLian.closeDao();
}

	protected void studentAdd(ActionEvent ve) {
		// TODO Auto-generated method stub
		String studentNumber= studentNumberTextField.getText().toString();
		String studentName= studentNameTextField.getText().toString();
		String birth= birthDateTextField.getText().toString();
		String political= politicalStatusTextField.getText().toString();
		String home= homeAddressTextField.getText().toString();
		String phone= phoneTextField.getText().toString();
		String dormId= dormIdTextField.getText().toString();
		@SuppressWarnings("deprecation")
		String password=new String(passwordField.getPassword());
		String gender=studentGenderManRadioButton.isSelected() ? studentGenderManRadioButton.getText():studentGenderWomanRadioButton.getText();
		if(StringUtil.isEmpty(studentNumber)){
			JOptionPane.showMessageDialog(null, "请填写学号!");
			return;
		}//弹出窗口
		if(StringUtil.isEmpty(studentName)){
			JOptionPane.showMessageDialog(null, "请填写学生姓名!");
			return;
		}//弹出消息对话框
		if(StringUtil.isEmpty(gender)){
			JOptionPane.showMessageDialog(null, "请选择性别!");
			return;
		}//弹出窗口
		if(StringUtil.isEmpty(birth)){
			JOptionPane.showMessageDialog(null, "请填写出生日期!");
			return;
		}//弹出窗口
		if(StringUtil.isEmpty(political)){
			JOptionPane.showMessageDialog(null, "请填写政治面貌!");
			return;
		}//弹出窗口
		if(StringUtil.isEmpty(home)){
			JOptionPane.showMessageDialog(null, "请填写家庭地址!");
			return;
		}//弹出窗口
		if(StringUtil.isEmpty(phone)){
			JOptionPane.showMessageDialog(null, "请填写电话!");
			return;
		}//弹出窗口
		if(StringUtil.isEmpty(dormId)){
			JOptionPane.showMessageDialog(null, "请填写宿舍号!");
			return;
		}//弹出窗口
		if(StringUtil.isEmpty(password)){
			JOptionPane.showMessageDialog(null, "请填写登录密码!");
			return;
		}//弹出窗口
		Student student=new Student();
		student.setName(studentName);
		student.setStudentNumber(studentNumber);
		student.setBirth(birth);
		student.setPolitical(political);
		student.setHomeAddress(home);
		student.setPhone(phone);
		student.setDormId(dormId);
		student.setGender(gender);
		student.setPassword(password);
		StudentLian studentLian=new StudentLian();
		if(studentLian.addStudent(student)) {
			JOptionPane.showMessageDialog(this,"添加成功!");
		setTable(student);
		}
		else {
			JOptionPane.showMessageDialog(this,"添加失败!");
		}
		resetValue(ve);
	}



	private void resetValue(ActionEvent ve) {
		// TODO Auto-generated method stub
		studentNameTextField.setText("");
		studentNumberTextField.setText("");
		birthDateTextField.setText("");
		politicalStatusTextField.setText("");
		homeAddressTextField.setText("");
		phoneTextField.setText("");
		dormIdTextField.setText("");
		genderButtonGroup.clearSelection();
		passwordField.setText("");
	}//清空文本,重置



	protected void aboutWriter(ActionEvent ce) {
		// TODO Auto-generated method stub
		String info="计科智能21-1的【乙女游戏爱好者】——马小童\n计科智能21-1的【橘子精】——石心田";
		//弹出窗口
		JOptionPane.showMessageDialog(this, info);
		URI uri;
		try {
			uri = new URI("https://www.bilibili.com/video/BV1Uv411H7KV?spm_id_from=333.337.search-card.all.click");
			Desktop desktop = Desktop.getDesktop(); 
			if(Desktop.isDesktopSupported()&&desktop.isSupported(Desktop.Action.BROWSE)) {
			try {
				desktop.browse(uri);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}}
		} catch (URISyntaxException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} //创建URI统一资源标识符	
	}
	private void setAuthority() {
		String x="学生";
		if(x.equals(userType.getName())) {
			//学生添加功能不可用
			increaseButton.setEnabled(false);
			//学生删除功能不可用
			 deleteButton.setEnabled(false);
		}
	}
}

五、静态扫描

在这里插入图片描述

六、系统演示视频

系统演示

七、项目Git地址及提交截图

https://gitee.com/l-big-cute/curriculum-design.git
在这里插入图片描述

在这里插入图片描述

总结

1.心得体会

通过此次课程设计,我们学会了很多GUI编程的知识,基本理解了与数据库相关的知识,将理论进行了实践,提高了编程的能力。在进行课程设计的过程中,遇到了许多困难,但通过思考、上网查阅资料,解决了困难,完成了课程设计。但仍有需要改进的地方,如:给每个界面设置背景图片,学生登陆页面可单独再设置一个页面,找回密码界面增加重置密码的功能,还应设计一个包含团队介绍的网页。此外,我们还可以增加筛选、修改密保问题答案等功能,可以将该项目做成网页版。

2.团队成员

团队成员职务负责模块个人博客地址
马小童组长数据库设计与连接、系统主界面设计、学生信息的增添、查询、修改、删除功能、实现网页的链接 、部分界面的连接个人博客
石心田组员登陆页面、注册页面、找回密码页面的设计及功能的实现、部分界面的连接个人博客
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值