欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

学生管理系统

程序员文章站 2022-09-13 23:08:25
学生管理系统后记可添加Maven依赖和HikariCP连接池界面数据库DAO类源码package ssm.dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import ssm.model.GradeType;import ssm.util.StringUtil;/** * * 班级类别类 * 对班级进行增删改查 * */...

学生管理系统

后记

可添加Maven依赖和HikariCP连接池

界面

学生管理系统
学生管理系统
学生管理系统
学生管理系统

数据库

学生管理系统
学生管理系统学生管理系统

DAO类源码

package ssm.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import ssm.model.GradeType;
import ssm.util.StringUtil;

/**
 * 
 * 班级类别类
 * 对班级进行增删改查
 *
 */
public class GradeTypeDao {
	/**
	 * 班级添加
	 */
	public int add(Connection con,GradeType gradeType)throws Exception{
		String sql = "INSERT INTO stu_grade VALUES(null,?,?,?)";//班级添加sql语句
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setString(1, gradeType.getCollege());
		ps.setString(2, gradeType.getGradeName());
		ps.setString(3, gradeType.getGradeDESC());
		return ps.executeUpdate();
	}
	/**
	 * 班级维护
	 */
	public ResultSet list(Connection con,GradeType gradeType)throws Exception{
		StringBuffer sb = new StringBuffer("SELECT * FROM stu_grade");
		if(StringUtil.isNotEmpty(gradeType.getGradeName())) {
			sb.append(" and gradeName like '%"+gradeType.getGradeName()+"%'");
		}
		PreparedStatement ps = con.prepareStatement(sb.toString().replaceFirst("and", "where"));
		return ps.executeQuery();
	}
	/**
	 * 班级删除
	 */
	public int delete(Connection con,String id)throws Exception{
		String sql = "DELETE FROM stu_grade WHERE id = ?";//删除sql语句
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setString(1, id);
		return ps.executeUpdate();
	}
	/**
	 * 班级修改
	 */
	public int update(Connection con,GradeType gradeType)throws Exception{
		String sql = "UPDATE stu_grade SET college=? , gradeName=? , gradeDESC=? WHERE id=?";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setString(1, gradeType.getCollege());
		ps.setString(2, gradeType.getGradeName());
		ps.setString(3, gradeType.getGradeDESC());
		ps.setInt(4, gradeType.getId());
		return ps.executeUpdate();
	}
}

package ssm.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import ssm.model.GradeType;
import ssm.model.Student;
import ssm.util.StringUtil;

/**
 * 
 * 对学生表进行增删改查
 *
 */
public class StudentDao {
	/**
	 * 添加学生信息
	 * @param con
	 * @param student
	 * @return
	 * @throws Exception
	 */
	public int add(Connection con,Student student)throws Exception{
		String sql = "INSERT INTO stu_student VALUES(null,?,?,?,?,?,?,?,?)";//学生添加sql语句
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setString(1, student.getStuName());
		ps.setString(2, student.getStuCollege());
		ps.setString(3, student.getStuIDcard());
		ps.setString(4, student.getStuAge());
		ps.setString(5, student.getStuGender());
		ps.setString(6, student.getStuAddress());
		ps.setString(7, student.getStuPhone());
		ps.setInt(8, student.getStuTypeid());
		return ps.executeUpdate();
	}
	/**
	 * 学生维护
	 */
	public ResultSet list(Connection con,Student student)throws Exception{
		StringBuffer sb = new StringBuffer("SELECT * FROM stu_student");
		if(StringUtil.isNotEmpty(student.getStuName())) {
			sb.append(" and stuName like '%"+student.getStuName()+"%'");
		}
		PreparedStatement ps = con.prepareStatement(sb.toString().replaceFirst("and", "where"));
		return ps.executeQuery();
	}
	/**
	 * 学生删除
	 */
	public int delete(Connection con,String id)throws Exception{
		String sql = "DELETE FROM stu_student WHERE id = ?";//删除sql语句
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setString(1, id);
		return ps.executeUpdate();
	}
	/**
	 * 学生修改
	 */
	public int update(Connection con,Student student)throws Exception{
		String sql = "UPDATE stu_student SET stuName=? , stuAge=? , stuGender=? , stuPhone=? , stuAddress=? , stuIDcard=? , stuCollege=? , stuTypeid=? WHERE id=?";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setString(1, student.getStuName());
		ps.setString(2, student.getStuAge());
		ps.setString(3, student.getStuGender());
		ps.setString(4, student.getStuPhone());
		ps.setString(5, student.getStuAddress());
		ps.setString(6, student.getStuIDcard());
		ps.setString(7, student.getStuCollege());
		ps.setInt(8, student.getStuTypeid());
		ps.setInt(9, student.getId());
		return ps.executeUpdate();
	}
}

package ssm.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import ssm.model.User;

/**
 * 
 * 用户访问数据库
 *
 */
public class UserDao {
/**
 * 登陆验证,判断用户名和密码
 */
	public User login(Connection con,User user)throws Exception{
		User resultUser = null;
		String sql = "SELECT * FROM stu_user WHERE username = ? AND password = ?";//查找数据库接口
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setString(1, user.getUserName());
		ps.setString(2, user.getPassWord());
		ResultSet rs = ps.executeQuery();
		if(rs.next()) {
			resultUser = new User();
			resultUser.setId(rs.getInt("id"));
			resultUser.setUserName(rs.getString("userName"));
			resultUser.setPassWord(rs.getString("passWord"));
		}
		return resultUser;
	}
}

model类

package ssm.model;

import javax.swing.JTextField;

/**
 * 
 * 班级分类实体
 *
 */
public class GradeType {
	private int id;//编号
	private String college;//学院名称
	private String gradeName;//班级名称
	private String gradeDESC;//班级备注
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getCollege() {
		return college;
	}
	public void setCollege(String college) {
		this.college = college;
	}
	public String getGradeName() {
		return gradeName;
	}
	public void setGradeName(String s_gradeName) {
		this.gradeName = s_gradeName;
	}
	public String getGradeDESC() {
		return gradeDESC;
	}
	public void setGradeDESC(String gradeDESC) {
		this.gradeDESC = gradeDESC;
	}
	//三个有参构造
	public GradeType(String college, String gradeName, String gradeDESC) {
		super();
		this.college = college;
		this.gradeName = gradeName;
		this.gradeDESC = gradeDESC;
	}
	//无参构造
	public GradeType() {
		super();
	}
	//四个有参构造
	public GradeType(int id, String college, String gradeName, String gradeDESC) {
		super();
		this.id = id;
		this.college = college;
		this.gradeName = gradeName;
		this.gradeDESC = gradeDESC;
	}
	public String toString() {
		return gradeName;
	}
}

package ssm.model;
/**
 * 
 * 学生分类实体
 *
 */
public class Student {
	private int id;//学生编号
	private String stuName;//学生姓名
	private String stuCollege;//学生学院
	private String stuIDcard;//学生学号
	private String stuAge;//学生年龄
	private String stuGender;//学生性别
	private String stuAddress;//学生地址
	private String stuPhone;//学生练习方式
	private int stuTypeid;//学生班级
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getStuName() {
		return stuName;
	}
	public void setStuName(String stuName) {
		this.stuName = stuName;
	}
	public String getStuCollege() {
		return stuCollege;
	}
	public void setStuCollege(String stuCollege) {
		this.stuCollege = stuCollege;
	}
	public String getStuIDcard() {
		return stuIDcard;
	}
	public void setStuIDcard(String stuIDcard) {
		this.stuIDcard = stuIDcard;
	}
	public String getStuAge() {
		return stuAge;
	}
	public void setStuAge(String stuAge) {
		this.stuAge = stuAge;
	}
	public String getStuGender() {
		return stuGender;
	}
	public void setStuGender(String stuGender) {
		this.stuGender = stuGender;
	}
	public String getStuAddress() {
		return stuAddress;
	}
	public void setStuAddress(String stuAddress) {
		this.stuAddress = stuAddress;
	}
	public String getStuPhone() {
		return stuPhone;
	}
	public void setStuPhone(String stuPhone) {
		this.stuPhone = stuPhone;
	}
	public int getStuTypeid() {
		return stuTypeid;
	}
	public void setStuTypeid(int stuTypeid) {
		this.stuTypeid = stuTypeid;
	}
	
	//构造有参->添加
	public Student(String stuName, String stuCollege, String stuIDcard, String stuAge, String stuGender,
			String stuAddress, String stuPhone, int stuTypeid) {
		super();
		this.stuName = stuName;
		this.stuCollege = stuCollege;
		this.stuIDcard = stuIDcard;
		this.stuAge = stuAge;
		this.stuGender = stuGender;
		this.stuAddress = stuAddress;
		this.stuPhone = stuPhone;
		this.stuTypeid = stuTypeid;
	}
	//构造无参
	public Student() {
		super();
		// TODO Auto-generated constructor stub
	}
	//构造有参->维护
	public Student(int id, String stuName, String stuCollege, String stuIDcard, String stuAge, String stuGender,
			String stuAddress, String stuPhone, int stuTypeid) {
		super();
		this.id = id;
		this.stuName = stuName;
		this.stuCollege = stuCollege;
		this.stuIDcard = stuIDcard;
		this.stuAge = stuAge;
		this.stuGender = stuGender;
		this.stuAddress = stuAddress;
		this.stuPhone = stuPhone;
		this.stuTypeid = stuTypeid;
	}
	
}

package ssm.model;
/**
 * 
 * 用户实体·用户名·密码
 *
 */
public class User {
	private int id;//编号
	private String userName;//用户名
	private String passWord;//密码
	private int is_admin;//管理员判定
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassWord() {
		return passWord;
	}
	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}
	public int getIs_admin() {
		return is_admin;
	}
	public void setIs_admin(int is_admin) {
		this.is_admin = is_admin;
	}
		
	public User() {
		super();
		// TODO Auto-generated constructor stub
	}
	public User(String userName, String passWord) {
		super();
		this.userName = userName;
		this.passWord = passWord;
	}

	
}

util类

package ssm.util;

import java.sql.Connection;
import java.sql.DriverManager;
/**
 * 
 * 连接数据库类
 *
 */
public class Jdbcutil {
	private String JdbcUrl = "jdbc:mysql://localhost:3306/SkingStudentManager?useSSL=false";//连接数据库,要在Url后面添加后缀跳过SSL验证
	private String JdbcUsername = "root";//数据库用户名
	private String JdbcPassword = "admin";//数据库密码
	private String JdbcName = "com.mysql.jdbc.Driver";//驱动名称
	
	//数据库连接
	public Connection getCon()throws Exception{
		Class.forName(JdbcName);
		Connection con = DriverManager.getConnection(JdbcUrl,JdbcUsername,JdbcPassword);
		return con;
	}
	
	//数据库关闭
	public void closeCon(Connection con)throws Exception{
		if(con != null) {
			con.close();
		}
	} 
	
	//测试数据库是否连接
	public static void main(String[] args) {
		Jdbcutil jdbcutil = new Jdbcutil();
		try {
			jdbcutil.getCon();
			System.out.println("数据库连接成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

package ssm.util;

/**
 * 
 * 处理字符串工具类
 *
 */
public class StringUtil {
	//判断是否为空
	public static boolean isEmpty(String str) {
		if(str == null || "".equals(str.trim())) {//trim函数->删除文本中除单词间的单个空格之外的所有空格
			return true;
		}else {
			return false;
		}
	}
	
	//判断不是空
	public static boolean isNotEmpty(String str) {
		if((str != null) && (!"".equals(str.trim()))) {
			return true;
		}else {
			return false;
		}
	}
}

view类

package ssm.view;
/**
 * 班级添加窗口
 */

import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import java.awt.Font;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.LineBorder;

import ssm.dao.GradeTypeDao;
import ssm.model.GradeType;
import ssm.util.Jdbcutil;
import ssm.util.StringUtil;

import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.awt.event.ActionEvent;

public class GradeTypeAddFrm extends JInternalFrame {
	private JTextField college;
	private JTextField gradeName;
	private JTextField gradeDESC;
	private Jdbcutil jdbcutil = new Jdbcutil();
	private GradeTypeDao gradeTypeDao = new GradeTypeDao(); 

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

	/**
	 * Create the frame.
	 */
	public GradeTypeAddFrm() {
		setClosable(true);
		setIconifiable(true);
		setTitle("班级添加");
		setBounds(100, 100, 450, 300);
		
		JLabel lblNewLabel = new JLabel("学院名称:");
		lblNewLabel.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		JLabel lblNewLabel_1 = new JLabel("班级名称:");
		lblNewLabel_1.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		JLabel lblNewLabel_2 = new JLabel("班级备注:");
		lblNewLabel_2.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		college = new JTextField();
		college.setColumns(10);
		
		gradeName = new JTextField();
		gradeName.setColumns(10);
		
		gradeDESC = new JTextField();
		gradeDESC.setColumns(10);
		
		JButton btnNewButton = new JButton("添加");
		btnNewButton.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				gradeTypeAddPerformed(e);
			}
		});
		
		JButton btnNewButton_1 = new JButton("重置");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				resetActionPerformed(e);
			}
		});
		btnNewButton_1.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(106)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(btnNewButton)
							.addPreferredGap(ComponentPlacement.RELATED, 98, Short.MAX_VALUE)
							.addComponent(btnNewButton_1))
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
								.addComponent(lblNewLabel_1)
								.addComponent(lblNewLabel)
								.addComponent(lblNewLabel_2))
							.addGap(18)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(gradeDESC, GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
								.addComponent(gradeName, GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
								.addComponent(college, GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE))))
					.addContainerGap(100, GroupLayout.PREFERRED_SIZE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(31)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel)
						.addComponent(college, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_1)
						.addComponent(gradeName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblNewLabel_2)
						.addComponent(gradeDESC, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE))
					.addGap(22)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnNewButton)
						.addComponent(btnNewButton_1))
					.addGap(28))
		);
		getContentPane().setLayout(groupLayout);
		
		//优化文本域边框
		gradeDESC.setBorder(new LineBorder(new java.awt.Color(127,157,185),1,false));
	}
	/**
	 * 班级添加操作
	 * @param e
	 */
	protected void gradeTypeAddPerformed(ActionEvent evt) {
		// TODO Auto-generated method stub
		String college = this.college.getText();//获得学院名称
		String gradeName = this.gradeName.getText();//获得班级名称
		String gradeDESC = this.gradeDESC.getText();//获得班级备注
		
		//判断是否为空
		if(StringUtil.isEmpty(college)) {
			JOptionPane.showMessageDialog(null, "请输入学院名称");
			return;
		}
		if(StringUtil.isEmpty(gradeName)) {
			JOptionPane.showMessageDialog(null, "请输入班级名称");
			return;
		}
		if(StringUtil.isEmpty(gradeDESC)) {
			JOptionPane.showMessageDialog(null, "请输入班级备注");
			return;
		}
		GradeType gradeType = new GradeType(college,gradeName,gradeDESC);
		Connection con = null;
		try {
			con = jdbcutil.getCon();
			int n = gradeTypeDao.add(con, gradeType);
			if(n == 1) {
				JOptionPane.showMessageDialog(null, "班级添加成功");
				this.resetValues();
			}else {
				JOptionPane.showMessageDialog(null, "班级添加失败");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				jdbcutil.closeCon(con);//关闭数据库
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * 重置添加操作
	 * @param e
	 */
	private void resetActionPerformed(ActionEvent evt) {
		// TODO Auto-generated method stub
		this.resetValues();
	}
	private void resetValues() {
			this.college.setText("");
			this.gradeName.setText("");
			this.gradeDESC.setText("");
	}
}

package ssm.view;
/**
 * 班级维护窗口
 */

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import java.awt.Font;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;

import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;

import ssm.dao.GradeTypeDao;
import ssm.model.GradeType;
import ssm.util.Jdbcutil;
import ssm.util.StringUtil;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class GradeTypeManageFrm extends JInternalFrame {
	private JTextField s_gradeName;
	private JTable gradeTypeTable;
	private Jdbcutil jdbcutil = new Jdbcutil();
	private GradeTypeDao gradeTypeDao = new GradeTypeDao(); 
	private JTextField updateid;
	private JTextField updatecollege;
	private JTextField updategradeName;
	private JTextField updategradeDESC;

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

	/**
	 * Create the frame.
	 */
	public GradeTypeManageFrm() {
		setClosable(true);
		setIconifiable(true);
		setTitle("班级维护");
		setBounds(100, 100, 550, 650);
		
		JLabel lblNewLabel = new JLabel("班级名称:");
		lblNewLabel.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		s_gradeName = new JTextField();
		s_gradeName.setColumns(10);
		
		JButton btnNewButton = new JButton("查询");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				gradeNameSearchAction(e);
			}
		});
		btnNewButton.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 20));
		
		JScrollPane scrollPane = new JScrollPane();
		
		JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "\u8868\u5355\u64CD\u4F5C", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		JButton btnNewButton_1 = new JButton("修改");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				gradeTypeUpdateActionEvent(e);
			}
		});
		btnNewButton_1.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 18));
		
		JButton btnNewButton_2 = new JButton("删除");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				gradeTypeDeleteActionPerformed(e);
			}
		});
		btnNewButton_2.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 18));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(94)
							.addComponent(lblNewLabel)
							.addGap(14)
							.addComponent(s_gradeName, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE)
							.addGap(41)
							.addComponent(btnNewButton))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(70)
							.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 389, GroupLayout.PREFERRED_SIZE))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(24)
							.addComponent(panel, GroupLayout.PREFERRED_SIZE, 480, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(30, Short.MAX_VALUE))
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(76)
					.addComponent(btnNewButton_1)
					.addPreferredGap(ComponentPlacement.RELATED, 247, Short.MAX_VALUE)
					.addComponent(btnNewButton_2)
					.addGap(73))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(48)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(s_gradeName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblNewLabel)))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(37)
							.addComponent(btnNewButton)))
					.addGap(18)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 256, GroupLayout.PREFERRED_SIZE)
					.addGap(32)
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 151, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(btnNewButton_1, Alignment.TRAILING)
						.addComponent(btnNewButton_2, Alignment.TRAILING))
					.addGap(11))
		);
		
		JLabel lblNewLabel_1 = new JLabel("班级编号:");
		lblNewLabel_1.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		updateid = new JTextField();
		updateid.setColumns(10);
		
		JLabel lblNewLabel_2 = new JLabel("学院名称:");
		lblNewLabel_2.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		updatecollege = new JTextField();
		updatecollege.setColumns(10);
		
		JLabel lblNewLabel_3 = new JLabel("班级名称:");
		lblNewLabel_3.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		updategradeName = new JTextField();
		updategradeName.setColumns(10);
		
		JLabel lblNewLabel_4 = new JLabel("班级备注:");
		lblNewLabel_4.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		updategradeDESC = new JTextField();
		updategradeDESC.setColumns(10);
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
					.addGap(36)
					.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(lblNewLabel_3)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(updategradeName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(lblNewLabel_1)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(updateid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addPreferredGap(ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
					.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
						.addComponent(lblNewLabel_4)
						.addComponent(lblNewLabel_2))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addComponent(updatecollege, GroupLayout.PREFERRED_SIZE, 98, GroupLayout.PREFERRED_SIZE)
						.addComponent(updategradeDESC, GroupLayout.PREFERRED_SIZE, 98, GroupLayout.PREFERRED_SIZE))
					.addGap(62))
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGap(10)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(updateid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNewLabel_2)
						.addComponent(updatecollege, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNewLabel_1))
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel.createSequentialGroup()
							.addGap(18)
							.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblNewLabel_4)
								.addComponent(updategradeName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblNewLabel_3)))
						.addGroup(gl_panel.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(updategradeDESC, GroupLayout.PREFERRED_SIZE, 67, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(12, Short.MAX_VALUE))
		);
		panel.setLayout(gl_panel);
		
		gradeTypeTable = new JTable();
		gradeTypeTable.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				gradeTypeTableMousePressed(e);
			}
		});
		gradeTypeTable.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u7F16\u53F7", "\u5B66\u9662\u540D\u79F0", "\u73ED\u7EA7\u540D\u79F0", "\u73ED\u7EA7\u5907\u6CE8"
			}
		));
		scrollPane.setViewportView(gradeTypeTable);
		getContentPane().setLayout(groupLayout);
		//调用初始化表格
		this.fillTable(new GradeType());

	}
	/**
	 * 删除事件(班级维护)
	 * @param e
	 */
	protected void gradeTypeDeleteActionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		String id = this.updateid.getText();//获得用户要删除的id
		if(StringUtil.isEmpty(id)) {
			JOptionPane.showMessageDialog(null, "请选择要删除的编号!");
			return;
		}
		int n = JOptionPane.showConfirmDialog(null, "确定要删除吗");
		if(n == 0) {
			Connection con = null;
			try {
				con = jdbcutil.getCon();
				//删除之前判断该班级之下是否
				//如果有学生就不删除
				int deleteNum = gradeTypeDao.delete(con, id);
				if(deleteNum == 1) {
					JOptionPane.showMessageDialog(null,"删除成功!");
					resetValue();
					fillTable(new GradeType());					
				}else {
					JOptionPane.showMessageDialog(null,"删除失败!");
				}
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}finally {
				try {
					jdbcutil.closeCon(con);
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		}
	}

	/**
	 * 修改事件(班级维护)
	 * @param e
	 */
	private void gradeTypeUpdateActionEvent(ActionEvent e) {
		// TODO Auto-generated method stub
		String id = updateid.getText();
		String college = updatecollege.getText();
		String gradeName = updategradeName.getText();
		String gradeDESC = updategradeDESC.getText();
		if(StringUtil.isEmpty(id)) {
			JOptionPane.showMessageDialog(null, "请选择要修改的编号!");
			return;
		}
		if(StringUtil.isEmpty(college)) {
			JOptionPane.showMessageDialog(null, "学院名称不能为空!");
			return;
		}
		if(StringUtil.isEmpty(gradeName)) {
			JOptionPane.showMessageDialog(null, "班级名称不能为空!");
			return;
		}
		if(StringUtil.isEmpty(gradeDESC)) {
			JOptionPane.showMessageDialog(null, "班级备注不能为空!");
			return;
		}
		GradeType gradeType = new GradeType(Integer.parseInt(id),college,gradeName,gradeDESC);
		Connection con = null;
		try {
			con = jdbcutil.getCon();
			int modifyNum = gradeTypeDao.update(con, gradeType);
			if(modifyNum == 1) {
				JOptionPane.showMessageDialog(null, "修改成功!");
				resetValue();
				fillTable(new GradeType());
			}else {
				JOptionPane.showMessageDialog(null, "修改失败!");
			}
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}finally {
			try {
				jdbcutil.closeCon(con);
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	/**
	 * 重置表单操作
	 */
	private void resetValue() {
		// TODO Auto-generated method stub
		this.updateid.setText("");
		this.updatecollege.setText("");
		this.updategradeName.setText("");
		this.updategradeDESC.setText("");
	}

	/**
	 * 表格单击事件,单机表格在下面显示信息
	 */
	
	private void gradeTypeTableMousePressed(MouseEvent evt) {
		// TODO Auto-generated method stub
		int row = gradeTypeTable.getSelectedRow();
		updateid.setText((String)gradeTypeTable.getValueAt(row, 0));
		updatecollege.setText((String)gradeTypeTable.getValueAt(row, 1));
		updategradeName.setText((String)gradeTypeTable.getValueAt(row, 2));
		updategradeDESC.setText((String)gradeTypeTable.getValueAt(row, 3));
	}
	
	/**
	 * 班级查询
	 * @param e
	 */
	private void gradeNameSearchAction(ActionEvent evt) {
		// TODO Auto-generated method stub
		String s_gradeName = this.s_gradeName.getText();
		GradeType gradeType = new GradeType();
		gradeType.setGradeName(s_gradeName);
		this.fillTable(gradeType);
		}
	
	/**
	 * 初始化表格
	 */
	private void fillTable(GradeType gradeType) {
		DefaultTableModel dtm = (DefaultTableModel)gradeTypeTable.getModel();
		dtm.setRowCount(0);
		Connection con = null;
		try {
			con = jdbcutil.getCon();
			ResultSet rs = gradeTypeDao.list(con, gradeType);
			while(rs.next()) {
					Vector v = new Vector();
					v.add(rs.getString("id"));
					v.add(rs.getString("college"));
					v.add(rs.getString("gradeName"));
					v.add(rs.getString("gradeDESC"));
					dtm.addRow(v);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				jdbcutil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	} 
}

package ssm.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

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

import ssm.dao.UserDao;
import ssm.model.User;
import ssm.util.Jdbcutil;
import ssm.util.StringUtil;

import javax.swing.JProgressBar;
import java.awt.Toolkit;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.awt.event.ActionEvent;

public class LogOnFrm extends JFrame {

	private JPanel contentPane;
	private JTextField username;
	private JPasswordField password;
	private Jdbcutil jdbcutil = new Jdbcutil();
	private UserDao userDao = new UserDao();
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					LogOnFrm frame = new LogOnFrm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public LogOnFrm() {
		setResizable(false);
		setIconImage(Toolkit.getDefaultToolkit().getImage(LogOnFrm.class.getResource("/ssm/images/标题.jpg")));
		setTitle("学生管理系统");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 430, 340);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JProgressBar progressBar = new JProgressBar();
		
		JLabel lblNewLabel = new JLabel("学生管理系统");
		lblNewLabel.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 21));
		
		JLabel lblNewLabel_1 = new JLabel("用户名");
		lblNewLabel_1.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 18));
		
		JLabel lblNewLabel_2 = new JLabel("密码");
		lblNewLabel_2.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 18));
		
		username = new JTextField();
		username.setColumns(10);
		
		password = new JPasswordField();
		
		JButton loginBut = new JButton("登陆");
		loginBut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				loginActionPerformed(e);
			}
		});
		loginBut.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 18));
		
		JButton retBut = new JButton("重置");
		retBut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				reSetActionPerformed(e);
			}
		});
		retBut.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 18));
		
		JLabel lblNewLabel_3 = new JLabel("生化环材机");
		lblNewLabel_3.setFont(new Font("Adobe 楷体 Std R", Font.PLAIN, 14));
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addComponent(progressBar, GroupLayout.PREFERRED_SIZE, 414, GroupLayout.PREFERRED_SIZE)
				.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
					.addContainerGap(166, Short.MAX_VALUE)
					.addComponent(lblNewLabel_3, GroupLayout.PREFERRED_SIZE, 113, GroupLayout.PREFERRED_SIZE)
					.addGap(135))
				.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
					.addGap(65)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addComponent(lblNewLabel_2)
						.addComponent(lblNewLabel_1)
						.addComponent(loginBut))
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
							.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 132, GroupLayout.PREFERRED_SIZE)
							.addGap(134))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
								.addComponent(password, Alignment.LEADING)
								.addComponent(username, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
								.addComponent(retBut))
							.addContainerGap(76, Short.MAX_VALUE))))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addComponent(progressBar, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGap(43)
					.addComponent(lblNewLabel)
					.addGap(27)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_1)
						.addComponent(username, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_2)
						.addComponent(password, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(loginBut)
							.addPreferredGap(ComponentPlacement.RELATED, 14, Short.MAX_VALUE))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(retBut)
							.addGap(18)))
					.addComponent(lblNewLabel_3))
		);
		contentPane.setLayout(gl_contentPane);
		//窗口居中显示
		this.setLocationRelativeTo(null);
	}
	
	/**
	 * 登录操作
	 * @param evt
	 */
	protected void loginActionPerformed(ActionEvent evt) {
		// TODO Auto-generated method stua
		 String userName = this.username.getText();
		 String passWord = new String(this.password.getText());
		 if(StringUtil.isEmpty(userName)) {
			 JOptionPane.showMessageDialog(null, "用户名不能为空");
			 return;
		 }
		 if(StringUtil.isEmpty(passWord)) {
			 JOptionPane.showMessageDialog(null, "密码不能为空");
			 return;
		 }
		 User user = new User(userName,passWord);
		 Connection con = null;//连接数据库
		 try {
			con = jdbcutil.getCon();
			User currenUser = userDao.login(con, user);
			if(currenUser != null) {
				dispose();//销毁当前窗口
				new MainFrm().setVisible(true);
			}else {
				JOptionPane.showMessageDialog(null, "用户名或密码错误");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				jdbcutil.closeCon(con);//关闭数据库
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * 重置操作
	 * @param e
	 */
	private void reSetActionPerformed(ActionEvent evt) {
		// TODO Auto-generated method stub
		this.username.setText("");
		this.password.setText("");		
	}
}

package ssm.view;
/**
 * 系统主界面
 */
import java.awt.BorderLayout;
import java.awt.EventQueue;

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

import ssm.model.GradeType;

import java.awt.Toolkit;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.awt.event.ActionEvent;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;

public class MainFrm extends JFrame {

	private JPanel contentPane;

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

	/**
	 * Create the frame.
	 */
	public MainFrm() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(MainFrm.class.getResource("/ssm/images/标题.jpg")));
		setTitle("主界面");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		//设置默认窗口最大化
		this.setExtendedState(JFrame.MAXIMIZED_BOTH);
		JDesktopPane table = new JDesktopPane();
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnNewMenu_3 = new JMenu("系统设置");
		menuBar.add(mnNewMenu_3);
		
		JMenuItem mntmNewMenuItem_5 = new JMenuItem("退出程序");
		mntmNewMenuItem_5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int result = JOptionPane.showConfirmDialog(null, "是否退出程序");
				if(result == 0) {
					dispose();
				}
			}
		});
		mnNewMenu_3.add(mntmNewMenuItem_5);
		
		JMenu mnNewMenu = new JMenu("班级管理");
		menuBar.add(mnNewMenu);
		
		JMenuItem mntmNewMenuItem = new JMenuItem("班级添加");
		mntmNewMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				GradeTypeAddFrm gradeTypeAddFrm = new GradeTypeAddFrm();
				gradeTypeAddFrm.setVisible(true);
				table.add(gradeTypeAddFrm);
			}
		});
		mnNewMenu.add(mntmNewMenuItem);
		
		JMenuItem mntmNewMenuItem_1 = new JMenuItem("班级维护");
		mntmNewMenuItem_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				GradeTypeManageFrm gradeTypeManageFrm = new GradeTypeManageFrm();
				gradeTypeManageFrm.setVisible(true);
				table.add(gradeTypeManageFrm);
			}
		});
		mnNewMenu.add(mntmNewMenuItem_1);
		
		JMenu mnNewMenu_1 = new JMenu("学生管理");
		menuBar.add(mnNewMenu_1);
		
		JMenuItem mntmNewMenuItem_2 = new JMenuItem("学生添加");
		mntmNewMenuItem_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				StudentAddFrm studentAddFrm = new StudentAddFrm();
				studentAddFrm.setVisible(true);
				table.add(studentAddFrm);
			}
		});
		mnNewMenu_1.add(mntmNewMenuItem_2);
		
		JMenuItem mntmNewMenuItem_3 = new JMenuItem("学生维护");
		mntmNewMenuItem_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				StudentManageFrm studentManageFrm = new StudentManageFrm();
				studentManageFrm.setVisible(true);
				table.add(studentManageFrm);
			}
		});
		mnNewMenu_1.add(mntmNewMenuItem_3);
		
		JMenu mnNewMenu_2 = new JMenu("关于我们");
		menuBar.add(mnNewMenu_2);
		
		JMenuItem mntmNewMenuItem_4 = new JMenuItem("提桶跑路");
		mntmNewMenuItem_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ssmInterFrm ssminter = new ssmInterFrm();
				ssminter.setVisible(true);
				table.add(ssminter);
			}
		});
		mnNewMenu_2.add(mntmNewMenuItem_4);
		
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		

		contentPane.add(table, BorderLayout.CENTER);
		table.setLayout(null);
	}
}

package ssm.view;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Font;
import javax.swing.LayoutStyle.ComponentPlacement;

public class ssmInterFrm extends JInternalFrame {

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

	/**
	 * Create the frame.
	 */
	public ssmInterFrm() {
		setClosable(true);
		setIconifiable(true);
		setTitle("提桶跑路");
		setBounds(100, 100, 450, 300);
		
		JLabel lblNewLabel = new JLabel("关山难越,谁悲失路之人;");
		lblNewLabel.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		JLabel lblNewLabel_1 = new JLabel("萍水相逢,尽是他乡之客。");
		lblNewLabel_1.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		JLabel lblNewLabel_2 = new JLabel("孟尝高洁,空余报国之情;");
		lblNewLabel_2.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		JLabel lblNewLabel_3 = new JLabel("阮籍猖狂,岂效穷途之哭!");
		lblNewLabel_3.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(111)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblNewLabel_1, GroupLayout.PREFERRED_SIZE, 231, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNewLabel_2, GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
						.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 244, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNewLabel_3, GroupLayout.PREFERRED_SIZE, 208, GroupLayout.PREFERRED_SIZE))
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblNewLabel_1, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
					.addGap(51)
					.addComponent(lblNewLabel_2, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(lblNewLabel_3, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(18, Short.MAX_VALUE))
		);
		getContentPane().setLayout(groupLayout);

	}
}

package ssm.view;

/**
 * 学生添加窗口
 */
import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;

import ssm.dao.GradeTypeDao;
import ssm.model.GradeType;
import ssm.model.Student;
import ssm.util.Jdbcutil;
import ssm.util.StringUtil;
import ssm.dao.StudentDao;

import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.awt.event.ActionEvent;
import javax.swing.JCheckBox;
import javax.swing.JFormattedTextField;
import javax.swing.JList;
import javax.swing.JComboBox;

public class StudentAddFrm extends JInternalFrame {
	private JTextField stuName;
	private JTextField stuAge;
	private JLabel lblNewLabel_3;
	private JTextField stuCollege;
	private JLabel lblNewLabel_4;
	private JTextField stuIDcard;
	private JLabel lblNewLabel_5;
	private JTextField stuAddress;
	private JLabel lblNewLabel_6;
	private JTextField stuPhone;
	private JLabel lblNewLabel_7;
	private JRadioButton stuGenderF;
	private final ButtonGroup buttonGroup_1 = new ButtonGroup();
	private JButton btnNewButton;
	private JButton btnNewButton_1;
	private Jdbcutil jdbcutil = new Jdbcutil();
	private GradeTypeDao gradeTypeDao = new GradeTypeDao();
	private JComboBox stuTypeid;
	private JRadioButton stuGenderM;
	private StudentDao studentDao = new StudentDao();

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

	/**
	 * Create the frame.
	 */
	public StudentAddFrm() {
		setClosable(true);
		setIconifiable(true);
		setTitle("学生添加");
		setBounds(100, 100, 541, 322);

		JLabel lblNewLabel = new JLabel("学生姓名:");
		lblNewLabel.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 14));

		stuName = new JTextField();
		stuName.setColumns(10);

		JLabel lblNewLabel_1 = new JLabel("学生年龄:");
		lblNewLabel_1.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 14));

		stuAge = new JTextField();
		stuAge.setColumns(10);

		JLabel lblNewLabel_2 = new JLabel("学生性别:");
		lblNewLabel_2.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 14));

		lblNewLabel_3 = new JLabel("学生学院:");
		lblNewLabel_3.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 14));

		stuCollege = new JTextField();
		stuCollege.setColumns(10);

		lblNewLabel_4 = new JLabel("学生学号:");
		lblNewLabel_4.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 14));

		stuIDcard = new JTextField();
		stuIDcard.setColumns(10);

		lblNewLabel_5 = new JLabel("学生地址:");
		lblNewLabel_5.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 14));

		stuAddress = new JTextField();
		stuAddress.setColumns(10);

		lblNewLabel_6 = new JLabel("学生联系方式:");
		lblNewLabel_6.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 14));

		stuPhone = new JTextField();
		stuPhone.setColumns(10);

		lblNewLabel_7 = new JLabel("学生班级:");
		lblNewLabel_7.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 14));

		stuGenderM = new JRadioButton("男");
		buttonGroup_1.add(stuGenderM);
		stuGenderM.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 14));

		stuGenderF = new JRadioButton("女");
		buttonGroup_1.add(stuGenderF);
		stuGenderF.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 14));

		btnNewButton = new JButton("添加");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				StudentAddActionPerformed(e);
			}
		});
		btnNewButton.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));

		btnNewButton_1 = new JButton("重置");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				StudentResetActionPerformed(e);
			}
		});
		btnNewButton_1.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));

		JList list = new JList();

		stuTypeid = new JComboBox();
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
						.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
								.addGroup(groupLayout.createSequentialGroup().addGap(21)
										.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
												.addComponent(lblNewLabel).addComponent(lblNewLabel_1))
										.addPreferredGap(ComponentPlacement.RELATED)
										.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
												.addComponent(stuAge, GroupLayout.PREFERRED_SIZE,
														GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
												.addComponent(stuName, GroupLayout.PREFERRED_SIZE,
														GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
								.addGroup(groupLayout.createSequentialGroup().addGap(18).addComponent(lblNewLabel_6)
										.addPreferredGap(ComponentPlacement.RELATED).addComponent(stuPhone,
												GroupLayout.PREFERRED_SIZE, 156, GroupLayout.PREFERRED_SIZE))
								.addGroup(groupLayout
										.createSequentialGroup().addGap(24).addComponent(lblNewLabel_4).addGap(2)
										.addComponent(stuIDcard, GroupLayout.PREFERRED_SIZE, 143,
												GroupLayout.PREFERRED_SIZE))
								.addGroup(groupLayout.createSequentialGroup().addGap(21).addComponent(lblNewLabel_5)
										.addPreferredGap(
												ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
										.addComponent(
												stuAddress, GroupLayout.PREFERRED_SIZE, 144, GroupLayout.PREFERRED_SIZE)
										.addGap(35))
								.addGroup(groupLayout.createSequentialGroup()
										.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
												.addGroup(groupLayout.createSequentialGroup().addGap(20)
														.addComponent(lblNewLabel_3))
												.addGroup(groupLayout.createSequentialGroup().addGap(21)
														.addComponent(lblNewLabel_2)))
										.addPreferredGap(ComponentPlacement.RELATED)
										.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
												.addGroup(groupLayout.createSequentialGroup().addComponent(stuGenderM)
														.addPreferredGap(ComponentPlacement.UNRELATED)
														.addComponent(stuGenderF))
												.addComponent(stuCollege, GroupLayout.PREFERRED_SIZE, 141,
														GroupLayout.PREFERRED_SIZE))))
						.addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout
								.createSequentialGroup().addGap(8)
								.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING).addComponent(btnNewButton)
										.addComponent(btnNewButton_1).addComponent(lblNewLabel_7))
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(stuTypeid, 0, 155, Short.MAX_VALUE))
								.addGroup(groupLayout.createSequentialGroup().addGap(55).addComponent(list,
										GroupLayout.PREFERRED_SIZE, 1, GroupLayout.PREFERRED_SIZE)))
						.addContainerGap()));
		groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout
				.createSequentialGroup().addContainerGap(16, Short.MAX_VALUE)
				.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel).addComponent(
						stuName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
				.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_1).addComponent(
						stuAge, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
				.addGap(11)
				.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup().addGap(3).addComponent(lblNewLabel_2).addGap(2)
								.addComponent(lblNewLabel_3).addGap(5).addComponent(lblNewLabel_4)
								.addPreferredGap(ComponentPlacement.RELATED).addComponent(lblNewLabel_5))
						.addGroup(
								groupLayout.createSequentialGroup()
										.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
												.addComponent(stuGenderM).addComponent(stuGenderF))
										.addPreferredGap(ComponentPlacement.RELATED)
										.addComponent(stuCollege, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(ComponentPlacement.UNRELATED)
										.addComponent(stuIDcard, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE)
										.addGap(13).addComponent(stuAddress, GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
				.addGap(1)
				.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_6).addComponent(
						stuPhone, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
				.addGap(32))
				.addGroup(groupLayout.createSequentialGroup().addContainerGap().addComponent(btnNewButton).addGap(18)
						.addComponent(btnNewButton_1).addGap(29)
						.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_7)
								.addComponent(stuTypeid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
										GroupLayout.PREFERRED_SIZE))
						.addGap(18).addComponent(list, GroupLayout.PREFERRED_SIZE, 1, GroupLayout.PREFERRED_SIZE)
						.addGap(105)));
		getContentPane().setLayout(groupLayout);
		// 调用初始化
		this.fillGradeType();
	}

	/**
	 * 添加事件
	 * 
	 * @param e
	 */
	private void StudentAddActionPerformed(ActionEvent evt) {
		// TODO Auto-generated method stub
		String stuName = this.stuName.getText();
		String stuCollege = this.stuCollege.getText();
		String stuAge = this.stuAge.getText();
		String stuPhone = this.stuPhone.getText();
		String stuAddress = this.stuAddress.getText();
		String stuIDcard = this.stuIDcard.getText();

		if (StringUtil.isEmpty(stuName)) {
			JOptionPane.showMessageDialog(null, "姓名不能为空!");
			return;
		}
		if (StringUtil.isEmpty(stuCollege)) {
			JOptionPane.showMessageDialog(null, "学院不能为空!");
			return;
		}
		if (StringUtil.isEmpty(stuPhone)) {
			JOptionPane.showMessageDialog(null, "联系方式不能为空!");
			return;
		}
		if (StringUtil.isEmpty(stuIDcard)) {
			JOptionPane.showMessageDialog(null, "学号不能为空!");
			return;
		}
		if (StringUtil.isEmpty(stuAddress)) {
			JOptionPane.showMessageDialog(null, "地址不能为空!");
			return;
		}
		if (StringUtil.isEmpty(stuAge)) {
			JOptionPane.showMessageDialog(null, "年龄不能为空!");
			return;
		}
		// 性别选择
		String stuGender = null;
		if (stuGenderM.isSelected()) {
			stuGender = "男";
		} else if (stuGenderF.isSelected()) {
			stuGender = "女";
		}
		// 获取班级
		GradeType gradeType = (GradeType) stuTypeid.getSelectedItem();
		int stuTypeid = gradeType.getId();

		// 将获取的数据放入表中
		Student student = new Student(stuName, stuCollege, stuIDcard, stuAge, stuGender, stuAddress, stuPhone,
				stuTypeid);
		Connection con = null;
		try {
			con = jdbcutil.getCon();
			int n = studentDao.add(con, student);
			if(n == 1) {
				JOptionPane.showMessageDialog(null, "添加成功");
				resetValues();
			}else {
				JOptionPane.showMessageDialog(null, "添加失败");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				jdbcutil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * 重置事件
	 * 
	 * @param e
	 */
	private void StudentResetActionPerformed(ActionEvent evt) {
		// TODO Auto-generated method stub
		this.resetValues();
	}

	private void resetValues() {
		// TODO Auto-generated method stub
		this.stuAddress.setText("");
		this.stuAge.setText("");
		this.stuCollege.setText("");
		this.stuIDcard.setText("");
		this.stuName.setText("");
		this.stuPhone.setText("");
	}

	/**
	 * 初始化班级下拉框
	 * 
	 * @param e
	 */
	private void fillGradeType() {
		Connection con = null;
		GradeType gradeType = null;
		try {
			con = jdbcutil.getCon();
			ResultSet rs = gradeTypeDao.list(con, new GradeType());
			while (rs.next()) {
				gradeType = new GradeType();
				gradeType.setId(rs.getInt("id"));
				gradeType.setGradeName(rs.getString("gradeName"));
				this.stuTypeid.addItem(gradeType);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				jdbcutil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}

package ssm.view;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import ssm.dao.GradeTypeDao;
import ssm.dao.StudentDao;
import ssm.model.GradeType;
import ssm.model.Student;
import ssm.util.Jdbcutil;
import ssm.util.StringUtil;

import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;

import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;

public class StudentManageFrm extends JInternalFrame {
	private JTable studentTable;
	private JTextField s_stuName;
	private JTextField updateStuGender;
	private JTextField updateStuAge;
	private JTextField updateStuIDcard;
	private JTextField updateStuPhone;
	private JTextField updateStuCollege;
	private JTextField updateStuGrade;
	private JTextField updateStuAddress;
	private Jdbcutil jdbcutil = new Jdbcutil();
	private StudentDao studentDao = new StudentDao();
	private Student student; 
	private JTextField updateStuName;
	private JTextField updateid;

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

	/**
	 * Create the frame.
	 */
	public StudentManageFrm() {
		setTitle("学生维护");
		setIconifiable(true);
		setClosable(true);
		setBounds(100, 100, 749, 801);
		
		JScrollPane scrollPane = new JScrollPane();
		
		studentTable = new JTable();
		studentTable.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				studentTableMousePressed(e);
			}
		});
		studentTable.setBackground(new Color(255, 255, 255));
		studentTable.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u59D3\u540D", "\u7F16\u53F7", "\u6027\u522B", "\u5E74\u9F84", "\u5B66\u53F7", "\u8054\u7CFB\u65B9\u5F0F", "\u5B66\u9662", "\u73ED\u7EA7", "\u901A\u8BAF\u5730\u5740"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, true, false, false, false, false, true, true
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		scrollPane.setViewportView(studentTable);
		
		JLabel lblNewLabel = new JLabel("学生姓名:");
		lblNewLabel.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		s_stuName = new JTextField();
		s_stuName.setColumns(10);
		
		JButton btnNewButton = new JButton("查询");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				studentSearchAction(e);
			}
		});
		btnNewButton.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		JLabel lblNewLabel_1 = new JLabel("性别:\r\n");
		lblNewLabel_1.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		updateStuGender = new JTextField();
		updateStuGender.setColumns(10);
		
		JLabel lblNewLabel_2 = new JLabel("年龄:");
		lblNewLabel_2.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		updateStuAge = new JTextField();
		updateStuAge.setColumns(10);
		
		JLabel lblNewLabel_3 = new JLabel("学号:");
		lblNewLabel_3.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		updateStuIDcard = new JTextField();
		updateStuIDcard.setColumns(10);
		
		JLabel lblNewLabel_4 = new JLabel("联系方式:");
		lblNewLabel_4.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		updateStuPhone = new JTextField();
		updateStuPhone.setColumns(10);
		
		JLabel lblNewLabel_5 = new JLabel("学院:");
		lblNewLabel_5.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		updateStuCollege = new JTextField();
		updateStuCollege.setColumns(10);
		
		JLabel lblNewLabel_6 = new JLabel("班级:");
		lblNewLabel_6.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		updateStuGrade = new JTextField();
		updateStuGrade.setColumns(10);
		
		JLabel lblNewLabel_7 = new JLabel("通讯地址:");
		lblNewLabel_7.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		updateStuAddress = new JTextField();
		updateStuAddress.setColumns(10);
		
		JButton btnNewButton_1 = new JButton("修改");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				studentUpdateActionEvent(e);
			}
		});
		btnNewButton_1.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 20));
		
		JButton btnNewButton_2 = new JButton("删除");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				studentDeleteActionPerformed(e);
			}
		});
		btnNewButton_2.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 20));
		
		JLabel lblNewLabel_8 = new JLabel("姓名:");
		lblNewLabel_8.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		updateStuName = new JTextField();
		updateStuName.setColumns(10);
		
		JLabel lblNewLabel_9 = new JLabel("编号:\r\n");
		lblNewLabel_9.setFont(new Font("Adobe 楷体 Std R", Font.BOLD, 16));
		
		updateid = new JTextField();
		updateid.setColumns(10);
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(112)
							.addComponent(lblNewLabel)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(s_stuName, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE)
							.addGap(109)
							.addComponent(btnNewButton))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(39)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblNewLabel_1)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(updateStuGender, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
									.addGap(172)
									.addComponent(lblNewLabel_4)
									.addGap(10)
									.addComponent(updateStuPhone, GroupLayout.PREFERRED_SIZE, 134, GroupLayout.PREFERRED_SIZE))
								.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 628, GroupLayout.PREFERRED_SIZE)
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblNewLabel_2)
									.addGap(3)
									.addComponent(updateStuAge, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
									.addGap(178)
									.addComponent(lblNewLabel_5)
									.addGap(34)
									.addComponent(updateStuCollege, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE))))
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(38)
									.addComponent(lblNewLabel_3)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(updateStuIDcard, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(36)
									.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
										.addGroup(groupLayout.createSequentialGroup()
											.addComponent(lblNewLabel_9)
											.addGap(5)
											.addComponent(updateid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
										.addGroup(groupLayout.createSequentialGroup()
											.addComponent(lblNewLabel_7)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(updateStuAddress, GroupLayout.PREFERRED_SIZE, 143, GroupLayout.PREFERRED_SIZE)))))
							.addGap(70)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblNewLabel_8)
									.addGap(39)
									.addComponent(updateStuName, GroupLayout.PREFERRED_SIZE, 118, GroupLayout.PREFERRED_SIZE))
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblNewLabel_6)
									.addGap(38)
									.addComponent(updateStuGrade, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE)))))
					.addContainerGap(66, Short.MAX_VALUE))
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(159)
					.addComponent(btnNewButton_1)
					.addPreferredGap(ComponentPlacement.RELATED, 229, Short.MAX_VALUE)
					.addComponent(btnNewButton_2)
					.addGap(199))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(39)
							.addComponent(lblNewLabel))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(40)
							.addComponent(s_stuName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(28)
							.addComponent(btnNewButton)))
					.addGap(17)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 302, GroupLayout.PREFERRED_SIZE)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(18)
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblNewLabel_1)
								.addComponent(updateStuGender, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(lblNewLabel_2))
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(11)
									.addComponent(updateStuAge, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
							.addGap(9)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(lblNewLabel_3)
								.addComponent(updateStuIDcard, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(20)
							.addComponent(lblNewLabel_4)
							.addGap(5)
							.addComponent(lblNewLabel_5)
							.addGap(8)
							.addComponent(lblNewLabel_6))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(19)
							.addComponent(updateStuPhone, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addGap(19)
							.addComponent(updateStuCollege, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addGap(22)
							.addComponent(updateStuGrade, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(8)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(lblNewLabel_7)
								.addComponent(updateStuAddress, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(lblNewLabel_9)
									.addGap(32)
									.addComponent(btnNewButton_1))
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(10)
									.addComponent(updateid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(6)
									.addComponent(lblNewLabel_8))
								.addGroup(groupLayout.createSequentialGroup()
									.addGap(7)
									.addComponent(updateStuName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
							.addGap(77)
							.addComponent(btnNewButton_2)))
					.addContainerGap(97, Short.MAX_VALUE))
		);
		getContentPane().setLayout(groupLayout);
		//调用初始化表格
		this.fillTable(new Student());

	}
	/**
	 * 修改事件(学生维护)
	 * @param e
	 */
	private void studentUpdateActionEvent(ActionEvent e) {
		// TODO Auto-generated method stub
		String id = updateid.getText();
		String college = updateStuCollege.getText();
		String grade = updateStuGrade.getText();
		String age = updateStuAge.getText();
		String gender = updateStuGender.getText();
		String phone = updateStuPhone.getText();
		String address = updateStuAddress.getText();
		String IDcard = updateStuIDcard.getText();
		String name = updateStuName.getText();
		if(StringUtil.isEmpty(id)) {
			JOptionPane.showMessageDialog(null, "请选择要修改的编号!");
			return;
		}
		if(StringUtil.isEmpty(college)) {
			JOptionPane.showMessageDialog(null, "学院名称不能为空!");
			return;
		}
		if(StringUtil.isEmpty(grade)) {
			JOptionPane.showMessageDialog(null, "班级名称不能为空!");
			return;
		}
		if(StringUtil.isEmpty(phone)) {
			JOptionPane.showMessageDialog(null, "联系方式不能为空!");
			return;
		}
		if(StringUtil.isEmpty(address)) {
			JOptionPane.showMessageDialog(null, "地址不能为空!");
			return;
		}
		if(StringUtil.isEmpty(IDcard)) {
			JOptionPane.showMessageDialog(null, "学号不能为空!");
			return;
		}
		if(StringUtil.isEmpty(gender)) {
			JOptionPane.showMessageDialog(null, "性别不能为空!");
			return;
		}
		if(StringUtil.isEmpty(name)) {
			JOptionPane.showMessageDialog(null, "姓名不能为空!");
			return;
		}
		if(StringUtil.isEmpty(age)) {
			JOptionPane.showMessageDialog(null, "年龄不能为空!");
			return;
		}
		Student student = new Student(Integer.parseInt(id),name,college,IDcard,age,gender,address,phone,Integer.parseInt(grade));
		Connection con = null;
		try {
			con = jdbcutil.getCon();
			int modifyNum = studentDao.update(con, student);
			if(modifyNum == 1) {
				JOptionPane.showMessageDialog(null, "修改成功!");
				resetValue();
				fillTable(new Student());
			}else {
				JOptionPane.showMessageDialog(null, "修改失败!");
			}
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}finally {
			try {
				jdbcutil.closeCon(con);
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	/**
	 * 删除事件(学生维护)
	 * @param e
	 */
	protected void studentDeleteActionPerformed(ActionEvent evt) {
		// TODO Auto-generated method stub
		String id = this.updateid.getText();//获得用户要删除的id
		if(StringUtil.isEmpty(id)) {
			JOptionPane.showMessageDialog(null, "请选择要删除的编号!");	
			return;
		}
		int n = JOptionPane.showConfirmDialog(null, "确定要删除吗");
		if(n == 0) {
			Connection con = null;
			try {
				con = jdbcutil.getCon();
				//判断是否删除成功
				if(studentDao.delete(con, id) == 1) {
					JOptionPane.showMessageDialog(null,"删除成功!");
					resetValue();
					fillTable(new Student());					
				}else {
					JOptionPane.showMessageDialog(null,"删除失败!");
				}		
				} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}finally {
				try {
					jdbcutil.closeCon(con);
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		}
	}
	/**
	 * 重置表单操作
	 */
	private void resetValue() {
		// TODO Auto-generated method stub
		this.updateid.setText("");
		this.updateStuCollege.setText("");
		this.updateStuName.setText("");
		this.updateStuPhone.setText("");
		this.updateStuAge.setText("");
		this.updateStuAddress.setText("");
		this.updateStuGender.setText("");
		this.updateStuGrade.setText("");
		this.updateStuIDcard.setText("");
	}
	/**
	 * 表格单击事件,单机表格在下面显示信息
	 */
	private void studentTableMousePressed(MouseEvent evt) {
		// TODO Auto-generated method stub
		int row =studentTable.getSelectedRow();
		updateStuName.setText((String)studentTable.getValueAt(row, 0));
		updateid.setText((String)studentTable.getValueAt(row, 1));
		updateStuGender.setText((String)studentTable.getValueAt(row, 2));
		updateStuAge.setText((String)studentTable.getValueAt(row, 3));
		updateStuIDcard.setText((String)studentTable.getValueAt(row,4));
		updateStuPhone.setText((String)studentTable.getValueAt(row, 5));
		updateStuCollege.setText((String)studentTable.getValueAt(row, 6));
		updateStuGrade.setText((String)studentTable.getValueAt(row, 7));
		updateStuAddress.setText((String)studentTable.getValueAt(row, 8));

	}
	/**
	 * 班级查询
	 * @param e
	 */
	private void studentSearchAction(ActionEvent evt) {
		// TODO Auto-generated method stub
		String s_stuName = this.s_stuName.getText();
		Student student = new Student();
		student.setStuName(s_stuName);
		this.fillTable(student);
		}
	/**
	 * 初始化表格
	 */
	private void fillTable(Student student) {
		DefaultTableModel dtm = (DefaultTableModel)studentTable.getModel();
		dtm.setRowCount(0);
		Connection con = null;
		try {
			con = jdbcutil.getCon();
			ResultSet rs =studentDao.list(con, student);
			while(rs.next()) {
					Vector v = new Vector();
					v.add(rs.getString("stuName"));
					v.add(rs.getString("id"));
					v.add(rs.getString("stuGender"));
					v.add(rs.getString("stuAge"));
					v.add(rs.getString("stuIDcard"));
					v.add(rs.getString("stuPhone"));
					v.add(rs.getString("stuCollege"));
					v.add(rs.getString("stuTypeid"));
					v.add(rs.getString("stuAddress"));
					dtm.addRow(v);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				jdbcutil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	} 
}

本文地址:https://blog.csdn.net/weixin_43914765/article/details/107160266