一、项目概要:
基于Java Swing企业员工信息管理系统,具备登录模块、员工信息管理、员工家庭管理、员工培训管理功能。
环境:Eclipse + JDK1.8 + Mysql 8.0 版本
二、获取方式:
如有需要可以点击直接下载 : 下载项目
如有技术问题,可咨询QQ:571328502
三、界面展示:
登录界面:
员工管理:
员工家庭管理:
员工培训管理:
四、主要代码:
package com.bj.view;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.UIManager;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import javax.swing.JPasswordField;
import com.bj.dao.LoginDao;
import com.bj.util.DBConnection;
import com.bj.util.Setting;
import com.bj.util.Tools;
import java.sql.Connection;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.SwingConstants;
import java.awt.Toolkit;
public class Login {
private JFrame frame;
private JPanel panel;
private JTextField textFieldNumber;
private JPasswordField passwordField;
private JButton btnLogin;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UIManager.put("RootPane.setupButtonVisible", false);
new Login();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "系统初始化错误!");
e.printStackTrace();
}
}
});
}
public Login() {
initialize();
event();
}
private void initialize() {
frame = new JFrame();
frame.setResizable(false);
frame.setAlwaysOnTop(true);
frame.setTitle("登录");
frame.setBounds(0, 0, 511, 293);
frame.setBounds(Tools.getScreenWidth()/2-frame.getWidth()/2, Tools.getScreenHeight()/2-frame.getHeight()/2, 411, 293);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
panel = new JPanel();
frame.getContentPane().add(panel);
panel.setLayout(null);
JLabel lblUsername = new JLabel("用户名:");
lblUsername.setFont(new Font("微软雅黑", Font.PLAIN, 16));
lblUsername.setBounds(74, 77, 54, 41);
panel.add(lblUsername);
JLabel lblPassword = new JLabel("密码:");
lblPassword.setFont(new Font("微软雅黑", Font.PLAIN, 16));
lblPassword.setBounds(74, 133, 54, 41);
panel.add(lblPassword);
btnLogin = new JButton("登录");
btnLogin.setFont(new Font("微软雅黑", Font.PLAIN, 20));
btnLogin.setBounds(119, 186, 179, 41);
panel.add(btnLogin);
frame.getRootPane().setDefaultButton(btnLogin);
textFieldNumber = new JTextField();
textFieldNumber.setBounds(138, 85, 160, 30);
panel.add(textFieldNumber);
passwordField = new JPasswordField();
passwordField.setBounds(138, 136, 160, 30);
panel.add(passwordField);
JLabel lblNewLabel = new JLabel("企业员工信息管理系统");
lblNewLabel.setForeground(new Color(0, 102, 255));
lblNewLabel.setFont(new Font("YaHei Consolas Hybrid", Font.BOLD, 30));
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setBounds(26, 10, 352, 51);
panel.add(lblNewLabel);
}
private void event(){
//如果配置文件不存在载入设置窗口
String dir = System.getProperty("user.dir");
File config = new File(dir+"/config.properties");
if(!config.exists()){
new Setting();
}
//登录按钮事件
btnLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if("".equals(textFieldNumber.getText())||"".equals(passwordField.getText())){
JOptionPane.showMessageDialog(frame, "请将信息填写完整");
return;
}
Connection con;
try {
con = DBConnection.getConnection();
try {
btnLogin.setEnabled(false);
boolean flag = new LoginDao().login(textFieldNumber.getText(), passwordField.getText());
if(flag) {
JOptionPane.showMessageDialog(Login.this.frame, "登录成功");
new MainWindow();
Login.this.frame.setVisible(false);
}else {
JOptionPane.showMessageDialog(Login.this.frame, "用户名或者密码错误");
}
} catch (Exception e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(Login.this.frame, "系统错误!");
return;
} finally{
btnLogin.setEnabled(true);
}
} catch (Exception e2) {
if(JOptionPane.showConfirmDialog(frame, "数据库连接失败,是否查看数据库配置?\n错误:"+e2.getMessage(), "提示:", JOptionPane.OK_CANCEL_OPTION)==0){
new Setting();
}
return;
}
}
});
}
}
五、其它项目:
基于Java Swing + Mysql 人事管理系统
六、心灵寄语:
想要赢,就一定不能怕输。不怕输结果未必能赢,但是怕输,结果则是一定输。