Eclipse+Java+Swing+mysql实现学生宿舍管理系统
- 一、系统介绍
- 1.环境配置
- 二、系统展示
- 1.登录页
- 2.学生主页面
- 3.学生端-登记页面
- 4.学生端-学生信息修改
- 5.学生端-寝室信息查询
- 6.学生端-学生信息查询
- 7.学生端-退出登录
- 8.管理员-主页面
- 9.管理员-宿舍信息修改
- 10.管理员-宿舍信息删除
- 11.管理员-学生信息修改
- 12.管理员-学生信息删除
- 13.管理员-宿舍信息添加
- 14.管理员-学生信息添加
- 15.管理员-学生信息查询
- 16.管理员-宿舍信息查询
- 17.管理员-关于系统
- 18.管理员-退出系统
- 三、部分代码
- RoomDao.java
- LoginFrame.java
- Room.java
- 四、其他
- 获取源码
一、系统介绍
本系统实现了学生登录和管理员登录,学生可以登记入住,实现学生信息查询和修改,实现宿舍信息查询。管理实现学生信息增删改查,实现宿舍信息增删改查。
1.环境配置
JDK版本:1.8
Mysql:5.7
二、系统展示
1.登录页
学生账号:学生,密码都是123
管理员账号:管理员,密码都是123456
2.学生主页面
3.学生端-登记页面
4.学生端-学生信息修改
5.学生端-寝室信息查询
6.学生端-学生信息查询
7.学生端-退出登录
8.管理员-主页面
9.管理员-宿舍信息修改
10.管理员-宿舍信息删除
11.管理员-学生信息修改
12.管理员-学生信息删除
13.管理员-宿舍信息添加
14.管理员-学生信息添加
15.管理员-学生信息查询
16.管理员-宿舍信息查询
17.管理员-关于系统
18.管理员-退出系统
三、部分代码
RoomDao.java
package cn.com.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import cn.com.model.Room;
import cn.com.util.StringUtil;
/**
*
* 操作宿舍信息
*
*/
public class RoomDao {
// 添加宿舍信息
public int roomAdd(Connection con, Room room) throws Exception {
String sql = "insert into room_message values(null,?,?)";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1, room.getMember());
pstmt.setString(2, room.getLeader());
return pstmt.executeUpdate();
}
// 查询宿舍信息
public ResultSet roomList(Connection con, Room room) throws Exception {
StringBuffer sb = new StringBuffer("select * from room_message");
if (StringUtil.isNotEmpty(room.getMember())) {
String member = room.getMember();
sb.append(" and member like '%" + room.getMember() + "%'");
}
PreparedStatement pstmt = con.prepareStatement(sb.toString().replaceFirst("and", "where"));
return pstmt.executeQuery();
}
// 修改宿舍信息
public int roomModify(Connection con, Room room) throws Exception {
String sql = "update room_message set member=?,leader=? where id=?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1, room.getMember());
pstmt.setString(2, room.getLeader());
pstmt.setString(3, room.getId());
return pstmt.executeUpdate();
}
// 删除宿舍信息
public int roomDelete(Connection con, Room room) throws Exception {
String sql = "delete from room_message where member=?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1, room.getMember());
return pstmt.executeUpdate();
}
}
LoginFrame.java
package cn.com.view;
import java.awt.Font;
import java.sql.Connection;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import cn.com.dao.UserDao;
import cn.com.model.User;
import cn.com.util.DBConn;
import cn.com.util.StringUtil;
/**
*
* 登录界面
*
*/
public class LoginFrm extends javax.swing.JFrame {
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JButton jb_login;
private JButton jb_reset;
private JComboBox jcb_choose;
private JTextField userNameTxt;
private JPasswordField userPasswordTxt;
DBConn dmutil = new DBConn();
UserDao userdao = new UserDao();
/**
* 创建窗体
*/
public LoginFrm() {
Font font = new Font("Dialog", Font.PLAIN, 12);
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key, font);
}
}
// 初始化
initComponents();
// 居中
this.setLocationRelativeTo(null);
this.filltable();
}
// 填充表格
private void filltable() {
User user1 = new User();
User user2 = new User();
user1.setUsername("学生");
user2.setUsername("管理员");
user1.setId(1 );
user2.setId(2 );
jcb_choose.addItem(user1);
jcb_choose.addItem(user2);
}
// 初始化
private void initComponents() {
jLabel1 = new JLabel("General", JLabel.CENTER);
jLabel2 = new JLabel();
jLabel3 = new JLabel();
userNameTxt = new JTextField();
userPasswordTxt = new JPasswordField();
jb_login = new JButton();
jb_reset = new JButton();
jcb_choose = new JComboBox();
jLabel4 = new JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("学生宿舍管理系统登录界面");
setResizable(false);
jLabel1.setFont(new Font("宋体", 0, 24));
jLabel1.setText("学生宿舍管理系统");
// 用户名
jLabel2.setText("账号:");
// 密码
jLabel3.setText("密码:");
userNameTxt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
userNameTxtActionPerformed(evt);
}
});
// 登录
jb_login.setText("登录");
jb_login.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_loginActionPerformed(evt);
}
});
// 重置
jb_reset.setText("重置");
jb_reset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_resetActionPerformed(evt);
}
});
jLabel4.setText("用户类型:");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup().addGap(103, 103, 103).addComponent(jLabel1)
.addContainerGap(58, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout
.createSequentialGroup().addGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING).addGroup(
layout.createSequentialGroup().addContainerGap().addComponent(
jLabel4).addGap(42, 42, 42).addComponent(jcb_choose,
javax.swing.GroupLayout.PREFERRED_SIZE, 111,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup().addGap(103, 103, 103)
.addGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel3).addComponent(jLabel2)))
.addGroup(layout
.createSequentialGroup().addGap(104, 104, 104)
.addComponent(jb_login)))
.addGroup(layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup().addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(userNameTxt,
javax.swing.GroupLayout.DEFAULT_SIZE,
111, Short.MAX_VALUE)
.addComponent(userPasswordTxt,
javax.swing.GroupLayout.DEFAULT_SIZE,
111, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup().addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jb_reset).addGap(25, 25, 25)))))
.addGap(100, 100, 100)));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
.createSequentialGroup().addGap(60, 60, 60).addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2)
.addComponent(userNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel3)
.addComponent(userPasswordTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel4)
.addComponent(jcb_choose, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(34, 34, 34).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jb_login).addComponent(jb_reset))
.addContainerGap(34, Short.MAX_VALUE)));
pack();
}
// 登录事件监控
private void jb_loginActionPerformed(java.awt.event.ActionEvent evt) {
String userName = userNameTxt.getText();
String userPassword = new String(userPasswordTxt.getPassword());
if (StringUtil.isEmpty(userName)) {
JOptionPane.showMessageDialog(null, "用户名不能为空!");
return;
} else if (StringUtil.isEmpty(userPassword)) {
JOptionPane.showMessageDialog(null, "密码不能为空!");
return;
}
User user = new User(userName, userPassword);
System.out.println("======xx===");
Connection con = null;
try {
con = dmutil.getConnection();
User currentuser = userdao.login(con, user);
System.out.println("========="+currentuser);
if ( null != currentuser) {
User user1 = (User) jcb_choose.getSelectedItem();
String userright = user1.getUsername();
if (userright.equals("管理员")) {
this.dispose();
MainFrm main = new MainFrm();
main.setVisible(true);
} else if (userright.equals("学生")) {
this.dispose();
MainFrm2 main2 = new MainFrm2();
main2.setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "用户名密码错误!");
}
}else {
JOptionPane.showMessageDialog(null, "用户名密码错误!");
}
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "登陆失败");
e.printStackTrace();
}
}
// 重置事件监控
private void jb_resetActionPerformed(java.awt.event.ActionEvent evt) {
this.userNameTxt.setText("");
this.userPasswordTxt.setText("");
}
private void userNameTxtActionPerformed(java.awt.event.ActionEvent evt) {
}
// 主函数
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LoginFrm().setVisible(true);
}
});
}
}
Room.java
package cn.com.model;
public class Room {
String id;// 寝室号
String member;// 成员
String leader;// 寝室长
// 构造函数
public Room(String member) {
super();
this.member = member;
}
public Room() {
super();
}
public Room(String id, String member, String leader) {
super();
this.id = id;
this.member = member;
this.leader = leader;
}
public Room(String member, String leader) {
super();
this.member = member;
this.leader = leader;
}
// get,set方法
public String getMember() {
return member;
}
public void setMember(String member) {
this.member = member;
}
public String getLeader() {
return leader;
}
public void setLeader(String leader) {
this.leader = leader;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String toString() {
return this.getMember();
}
}
四、其他
获取源码
点击以下链接获取源码。
Java+Swing+Txt实现自助款机系统
Java+Swing+Mysql自助存取款机系统
Java+Swing+mysql5实现学生成绩管理系统(带分页)
Java+Swing+Mysql实现超市商品管理系统源码
Java+Swing+Mysql实现通讯录管理系统源码
Java+Swing+Mysql实现图书管理系统源码