- 一、系统介绍
- 1.系统功能
- 2.环境配置
- 3.数据库
- 4.工程截图
- 二、系统展示
- 1.登录页
- 1.1登录成功
- 2.添加年级
- 3.管理年级
- 4.新增班级
- 5.管理班级
- 6.添加学生
- 7.管理学生信息
- 8.退出系统
- 9.关于我们
- 三、部分代码
- DBConn.java
- LoginFrm.java
- Student.java
- 四、其他
- 获取源码
一、系统介绍 1.系统功能
1.登录系统
2.添加年级
3.管理年级信息
4.添加班级
5.管理班级信息
6.添加学生
7.管理学生信息
8.退出系统
9.关于我们
JDK版本:1.8
Mysql:5.7
; ; ; ; ; ; CREATE DATABASE `swing_student` ; USE `swing_student`; DROP TABLE IF EXISTS `class`; CREATE TABLE `class` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) DEFAULT NULL, `desc` varchar(20) DEFAULT NULL, `grade_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `FK_class` (`grade_id`), CONSTRAINT `FK_class` FOREIGN KEY (`grade_id`) REFERENCES `grade` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8; insert into `class`(`id`,`name`,`desc`,`grade_id`) values (1,'一年级1班','1-1',1),(2,'一年级2班','1-2',1),(3,'一年级3班','1-3',1),(4,'二年级1班','2-1',2),(5,'二年级2班','2-2',2),(6,'二年级3班','2-3',2),(7,'三年级1班','3-1',3),(8,'三年级2班','3-2',3); DROP TABLE IF EXISTS `grade`; CREATE TABLE `grade` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) DEFAULT NULL, `desc` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; insert into `grade`(`id`,`name`,`desc`) values (1,'一年级','1年级'),(2,'二年级','2'),(3,'三年级','3'); DROP TABLE IF EXISTS `student`; CREATE TABLE `student` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) DEFAULT NULL, `number` int(11) DEFAULT NULL, `birthday` date DEFAULT NULL, `place` varchar(100) DEFAULT NULL, `class_id` int(11) DEFAULT NULL, `desc` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`), KEY `FK_student` (`class_id`), CONSTRAINT `FK_student` FOREIGN KEY (`class_id`) REFERENCES `class` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; insert into `student`(`id`,`name`,`number`,`birthday`,`place`,`class_id`,`desc`) values (1,'张三',1001,'1990-01-01','北京',1,'1年级1班 班长'),(2,'李四',2001,'1990-01-01','上海',4,'2年级1班 班长'); DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(20) DEFAULT NULL, `userpass` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; insert into `user`(`id`,`username`,`userpass`) values (1,'admin','123456'); ; ; ; ;4.工程截图 二、系统展示 1.登录页 1.1登录成功 2.添加年级 3.管理年级 4.新增班级 5.管理班级 6.添加学生 7.管理学生信息 8.退出系统 9.关于我们 三、部分代码 DBConn.java
package cn.com.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
public class DBConn {
private static String driverName = "com.mysql.jdbc.Driver";
private static String url = "jdbc:mysql://localhost:3306/swing_student?characterEncoding=utf8";
private static String userName = "root";
private static String password = "root";
private Connection conn;
private Statement stmt;
public DBConn() {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public Connection getConnection() throws SQLException {
return DriverManager.getConnection(url, userName, password);
}
public void close() {
try {
if (conn != null) {
conn.close();
}
if (stmt != null) {
stmt.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
LoginFrm.java
package cn.com.view;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import cn.com.dao.UserDao;
import cn.com.model.User;
import cn.com.util.DBConn;
import cn.com.util.StringUtil;
public class LoginFrm extends JFrame {
private JPanel contentPane;
private JTextField username_txt;
private JPasswordField password_txt;
private DBConn db=new DBConn();
private UserDao userDao=new UserDao();
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LoginFrm frame = new LoginFrm();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public LoginFrm() {
setResizable(false);
setTitle("u7BA1u7406u5458u767Bu5F55");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
JLabel lblNewLabel = new JLabel("u5B66u751Fu7BA1u7406u7CFBu7EDF");
lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 24));
JLabel lblNewLabel_1 = new JLabel("u7528u6237u540D:");
JLabel lblNewLabel_2 = new JLabel("u5BC6u7801:");
username_txt = new JTextField();
username_txt.setColumns(10);
password_txt = new JPasswordField();
JButton btnNewButton = new JButton("u767Bu5F55");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
LoginActionPerformed(e);
}
});
JButton btnNewButton_1 = new JButton("u91CDu7F6E");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ResetActionPerformed(e);
}
});
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(114)
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblNewLabel_2)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(password_txt, 224, 224, 224)
.addPreferredGap(ComponentPlacement.RELATED))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblNewLabel_1)
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel)
.addComponent(username_txt, 226, 226, 226))))
.addGap(48))
.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
.addGap(153)
.addComponent(btnNewButton)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(btnNewButton_1)
.addContainerGap(157, Short.MAX_VALUE))
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(50)
.addComponent(lblNewLabel)
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_1)
.addComponent(username_txt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_2)
.addComponent(password_txt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(btnNewButton)
.addComponent(btnNewButton_1))
.addContainerGap(60, Short.MAX_VALUE))
);
contentPane.setLayout(gl_contentPane);
this.setLocationRelativeTo(null);
}
protected void ResetActionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
this.username_txt.setText("");
this.password_txt.setText("");
}
protected void LoginActionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String username=this.username_txt.getText();
String password=new String(this.password_txt.getPassword());
if(StringUtil.isEmpty(username)) {
JOptionPane.showMessageDialog(null, "用户名不能为空");
return;
}
if(StringUtil.isEmpty(password)) {
JOptionPane.showMessageDialog(null, "密码不能为空");
return;
}
User user=new User(username,password);
Connection conn=null;
try {
conn=db.getConnection();
User current_user=userDao.login(conn,user);
if(current_user!=null) {
JOptionPane.showMessageDialog(null, "登录成功");
dispose();
new MainFrm().setVisible(true);
}else {
JOptionPane.showMessageDialog(null, "用户名或者密码错误");
}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
Student.java
package cn.com.model;
public class Student {
private int id;
private Integer number;
private String name;
private String birthday;
private String place;
private Integer class_id;
private String class_name;
private String desc;
public Student() {
super();
// TODO Auto-generated constructor stub
}
public Student(String name, Integer number, String birthday, String place, Integer class_id, String desc) {
super();
this.name = name;
this.number = number;
this.birthday = birthday;
this.place = place;
this.class_id = class_id;
this.desc = desc;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
public Integer getClass_id() {
return class_id;
}
public void setClass_id(Integer class_id) {
this.class_id = class_id;
}
public String getClass_name() {
return class_name;
}
public void setClass_name(String class_name) {
this.class_name = class_name;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
四、其他
获取源码
点击以下链接获取源码,数据库文件在swing_student.sql文件里面。
Java+Swing+mysql5实现学生管理系统
Java+Swing+Mysql实现图书管理系统源码
Java+Swing+Mysql实现通讯录管理系统源码



