Java+Swing+MySQL大学生学籍管理系统

目录

一、系统介绍

1.运行环境

2.技术说明

3.系统功能

4.数据库

二、系统实现 

总体功能框架

三、部分代码 

ClassAddInter .java

 ClassDelInter.java

login.java


一、系统介绍

1.运行环境

开发工具:Eclipse/IDEA

JDK版本:jdk1.8

Mysql版本:5.7

2.技术说明

Java+Swing+Mysql

3.系统功能

学生管理模块:实现对学生信息的添加、查询、修改、删除操作

课程管理模块:实现对课程信息的添加、查询、修改、删除操作

院系管理模块:实现对院系信息的添加、查询、删除操作

专业管理模块:实现对专业信息的添加、查询、删除操作

班级管理模块:实现对班级信息的添加、删除、查询班级人数操作

选课管理模块:实现对选课信息的添加、查询、删除操作

成绩管理模块:实现对成绩信息的添加、查询、修改、删除操作

奖惩管理模块:实现对奖惩信息的添加、查询、修改、删除操作

4.数据库

·学生信息表(stu_inf):

字段名

字段类型

小数点

是否主键

是否为空

是否外键

备注

Sno

Varchar(6)

学号

Sname

Varchar(10)

姓名

Ssex

Enum

性别

Sbirth

Date

出生年月

Snative

Varchar(10)

籍贯

Sclass

Int

班级

Smajor

Varchar(10)

专业

外键:

字段

被引用的模式

被引用的表(父)

被引用的字段

删除时

更新时

inf-class

Sclass, Smajor

meimaobingle

class

classnum, majorname

RESTRICT

RESTRICT

·课程信息表(course):

字段名

字段类型

小数点

是否主键

是否为空

是否外键

备注

Cno

Varchar(4)

课程号

Cname

Varchar(40)

课程名

Ccredit

Smallint

学分

Cteacher

Varchar(10)

执教教师

·院系信息表(department):

字段名

字段类型

小数点

是否主键

是否为空

是否外键

备注

departname

Varchar(10)

院系名

·专业信息表(major):

字段名

字段类型

小数点

是否主键

是否为空

是否外键

备注

majorname

Varchar(10)

专业名

departname

Varchar(10)

院系名

外键:

字段

被引用的模式

被引用的表(父)

被引用的字段

删除时

更新时

major-depart

departname

meimaobingle

department

departname

CASCADE

CASCADE

·班级信息表(class):

字段名

字段类型

小数点

是否主键

是否为空

是否外键

备注

majorname

Varchar(10)

专业名

classnum

Int

班级号

classsum

Smallint

班级人数

外键:

字段

被引用的模式

被引用的表(父)

被引用的字段

删除时

更新时

class-major

majorname

meimaobingle

major

majorname

CASCADE

CASCADE

·选课信息表(stu_cou):

字段名

字段类型

小数点

是否主键

是否为空

是否外键

备注

Cno

Varchar(4)

课程号

Sno

Varchar(6)

学号

Grade

Smallint

成绩

外键:

字段

被引用的模式

被引用的表(父)

被引用的字段

删除时

更新时

cou_course

Cname, Cno

meimaobingle

course

Cname, Cno

CASCADE

CASCADE

cou_inf

Sno

meimaobingle

stu_inf

Sno

CASCADE

CASCADE

·奖惩信息表(stu_san):

字段名

字段类型

小数点

是否主键

是否为空

是否外键

备注

id

int

奖惩ID

Sno

Varchar(6)

学号

Sname

Varchar(10)

姓名

Reward

Varchar(100)

奖励信息

Punish

Varchar(100)

惩罚信息

外键:

字段

被引用的模式

被引用的表(父)

被引用的字段

删除时

更新时

san-inf

Sno, Sname

meimaobingle

stu_inf

Sno, Sname

CASCADE

CASCADE

·用户信息表(login):

字段名

字段类型

小数点

是否主键

是否为空

是否外键

备注

username

Varchar(10)

用户名

password

Varchar(10)

密码

二、系统实现 

运行界面及其效果图

总体功能框架

 

三、部分代码 

ClassAddInter .java

package 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.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;

import util.Data;

import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;

public class ClassAddInter extends JInternalFrame {
	private JTextField TextMajor;
	private JTextField TextClassnum;

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

	/**
	 * Create the frame.
	 */
	public ClassAddInter() {
		setTitle("\u6DFB\u52A0\u73ED\u7EA7");
		setBounds(100, 100, 450, 300);
		
		JLabel lblNewLabel = new JLabel("\u4E13\u4E1A\u540D");
		lblNewLabel.setFont(new Font("楷体", Font.PLAIN, 13));
		
		JLabel lblNewLabel_1 = new JLabel("\u73ED\u7EA7\u53F7");
		lblNewLabel_1.setFont(new Font("楷体", Font.PLAIN, 13));
		
		TextMajor = new JTextField();
		TextMajor.setColumns(10);
		
		TextClassnum = new JTextField();
		TextClassnum.setColumns(10);
		
		JButton btnNewButton = new JButton("\u6DFB\u52A0\u73ED\u7EA7");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				String major=TextMajor.getText();
				Data db = new Data();
				int classnum=-1;
				try {
					classnum = Integer.parseInt(TextClassnum.getText());
				} catch (NumberFormatException e2) {
					// TODO Auto-generated catch block
					JOptionPane.showMessageDialog(null, "班级号格式得正确!");
					e2.printStackTrace();
				}
				 
				
				String sql1="insert into class(majorname,classnum) values('"+major+"',"+classnum+")";
				try {
					int i = db.updateSQL(sql1);
					if(i!=0) JOptionPane.showMessageDialog(null, "添加成功");
					else JOptionPane.showMessageDialog(null, "格式不正确,无法添加");
				} catch (Exception e1) {
					JOptionPane.showMessageDialog(null, "格式不正确,无法添加");
					e1.printStackTrace();
					// TODO Auto-generated catch block
				}
				try {
					db.closeConnection();
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				finally {
					TextMajor.setText("");
					TextClassnum.setText("");
				}
				
				
				
			}
		});
		btnNewButton.setFont(new Font("楷体", Font.PLAIN, 14));
		
		JButton btnNewButton_1 = new JButton("\u9000\u51FA");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		btnNewButton_1.setFont(new Font("楷体", Font.PLAIN, 14));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(49)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 106, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED, 120, Short.MAX_VALUE)
							.addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 95, GroupLayout.PREFERRED_SIZE)
							.addGap(64))
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
								.addComponent(lblNewLabel_1)
								.addComponent(lblNewLabel))
							.addGap(28)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
								.addComponent(TextClassnum)
								.addComponent(TextMajor, GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE))
							.addContainerGap(165, Short.MAX_VALUE))))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(43)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel)
						.addComponent(TextMajor, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(30)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_1)
						.addComponent(TextClassnum, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED, 69, Short.MAX_VALUE)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE))
					.addGap(43))
		);
		getContentPane().setLayout(groupLayout);

	}
}

 ClassDelInter.java

package 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.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;

import util.Data;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ClassDelInter extends JInternalFrame {
	private JTextField TextMajor;
	private JTextField TextClassnum;

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

	/**
	 * Create the frame.
	 */
	public ClassDelInter() {
		setTitle("\u5220\u9664\u73ED\u7EA7");
		setBounds(100, 100, 450, 300);
		
		JLabel lblNewLabel = new JLabel("\u4E13\u4E1A\u540D");
		lblNewLabel.setFont(new Font("楷体", Font.PLAIN, 13));
		
		JLabel lblNewLabel_1 = new JLabel("\u73ED\u7EA7\u53F7");
		lblNewLabel_1.setFont(new Font("楷体", Font.PLAIN, 14));
		
		TextMajor = new JTextField();
		TextMajor.setColumns(10);
		
		TextClassnum = new JTextField();
		TextClassnum.setColumns(10);
		
		JButton btnNewButton = new JButton("\u5220\u9664");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				 
				
				Data db = new Data();
				int classnum=-1;
				try {
					classnum = Integer.parseInt(TextClassnum.getText());
				} catch (NumberFormatException e2) {
					// TODO Auto-generated catch block
					JOptionPane.showMessageDialog(null, "班级号格式得正确!");
					e2.printStackTrace();
				}
				String major=TextMajor.getText();
				String sql="delete from class where classnum="+classnum+" and majorname='"+major+"'";
				try {
					int i = db.updateSQL(sql);
					if(i!=0) JOptionPane.showMessageDialog(null, "删除成功");
					else JOptionPane.showMessageDialog(null, "删除失败","删除操作",JOptionPane.INFORMATION_MESSAGE);
				} catch (Exception e1) {
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null, "删除失败","删除操作",JOptionPane.INFORMATION_MESSAGE);
					// TODO Auto-generated catch block
				}
				try {
					db.closeConnection();
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				finally {
					TextClassnum.setText("");
					TextMajor.setText("");
				}
				
				
			}
		});
		btnNewButton.setFont(new Font("楷体", Font.PLAIN, 14));
		
		JButton btnNewButton_1 = new JButton("\u9000\u51FA");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		btnNewButton_1.setFont(new Font("楷体", Font.PLAIN, 14));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
					.addGap(81)
					.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 89, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED, 79, Short.MAX_VALUE)
					.addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 84, GroupLayout.PREFERRED_SIZE)
					.addGap(101))
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(56)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblNewLabel)
						.addComponent(lblNewLabel_1))
					.addGap(26)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
						.addComponent(TextClassnum)
						.addComponent(TextMajor, GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE))
					.addContainerGap(188, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(28)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(TextMajor, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(lblNewLabel)
							.addGap(32)
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblNewLabel_1)
								.addComponent(TextClassnum, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
					.addPreferredGap(ComponentPlacement.RELATED, 71, Short.MAX_VALUE)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 53, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 52, GroupLayout.PREFERRED_SIZE))
					.addGap(51))
		);
		getContentPane().setLayout(groupLayout);

	}

}

login.java

package view;

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

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

import util.Data;

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

import java.awt.Color;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import javax.swing.JTextField;
import javax.swing.JPasswordField;

public class login extends JFrame {

	/**
	 * 
	 * 登录页面
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField TextUsername;
	private JPasswordField TextPassword;

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

	/**
	 * Create the frame.
	 */
	public login() {
		setTitle("\u767B\u5F55\u9875\u9762");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel welcome = new JLabel("\u6B22\u8FCE\u767B\u5F55\u77F3\u6CB9\u5927\u5B66\u5B66\u751F\u5B66\u7C4D\u7CFB\u7EDF");
		welcome.setFont(new Font("宋体", Font.PLAIN, 15));
		welcome.setBackground(Color.WHITE);
		welcome.setLabelFor(contentPane);
		
		JButton loginBtn = new JButton("\u767B\u5F55");
		loginBtn.setToolTipText("");
		loginBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				String userName=TextUsername.getText();
				@SuppressWarnings("deprecation")
				String Password=TextPassword.getText();
				Data db=new Data();
				String sql="select* from login where username='"+userName+"' and password='"+Password+"'";
				ResultSet rs = db.getResult(sql);
				try {
					if(rs.next()){
						db.closeConnection();
						if(JOptionPane.showConfirmDialog(null, "登录成功")==0)
						{
							dispose();
							MainFrm main=new MainFrm();
							main.setVisible(true);
						}	
					}
					else	
						{
							JOptionPane.showMessageDialog(null, "请输入正确的管理员信息");
							TextUsername.setText("");
							TextPassword.setText("");
						}
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					JOptionPane.showMessageDialog(null, "请输入正确的管理员信息");
					TextUsername.setText("");
					TextPassword.setText("");
					e1.printStackTrace();
				}
		
			}
		});
		
		JButton exitBtn = new JButton("\u9000\u51FA");
		exitBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int i=JOptionPane.showConfirmDialog(null,"不会吧,这就有人要退了?","提示", JOptionPane.YES_NO_OPTION);
				if(i==0)	System.exit(0);
			}
		});
		
		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon(login.class.getResource("/image/none.ico")));
		
		JLabel lblNewLabel_1 = new JLabel("\u7BA1\u7406\u5458\u8D26\u53F7");
		
		JLabel lblNewLabel_2 = new JLabel("\u7BA1\u7406\u5458\u5BC6\u7801");
		
		TextUsername = new JTextField();
		TextUsername.setColumns(10);
		
		TextPassword = new JPasswordField();
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap(102, Short.MAX_VALUE)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(welcome, GroupLayout.PREFERRED_SIZE, 292, GroupLayout.PREFERRED_SIZE)
							.addGap(30))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(lblNewLabel)
							.addGap(180))))
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(81)
					.addComponent(loginBtn, GroupLayout.PREFERRED_SIZE, 69, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED, 130, Short.MAX_VALUE)
					.addComponent(exitBtn, GroupLayout.PREFERRED_SIZE, 73, GroupLayout.PREFERRED_SIZE)
					.addGap(71))
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(65)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addComponent(lblNewLabel_2)
						.addComponent(lblNewLabel_1))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
						.addComponent(TextPassword)
						.addComponent(TextUsername, GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE))
					.addContainerGap(140, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(welcome, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
					.addGap(18)
					.addComponent(lblNewLabel)
					.addGap(20)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_1)
						.addComponent(TextUsername, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(26)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_2)
						.addComponent(TextPassword, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(37)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(loginBtn, GroupLayout.DEFAULT_SIZE, 38, Short.MAX_VALUE)
						.addComponent(exitBtn, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE))
					.addGap(37))
		);
		contentPane.setLayout(gl_contentPane);
	}
}

猜你喜欢

转载自blog.csdn.net/qq_61827376/article/details/125368341