JDBCUtils.java
package com.sjsq.tools; import com.alibaba.druid.pool.DruidDataSourceFactory; import javax.sql.DataSource; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; /** * Druid连接池工具类,将来dao层调用 */ public class JDBCUtils { private static DataSource dataSource; // 定义成员变量DataSource static { try { // 加载配置文件 Properties properties = new Properties(); properties.load(JDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties")); // 获取DataSource dataSource = DruidDataSourceFactory.createDataSource(properties); } catch (Exception e) { e.printStackTrace(); } } /** * 获取连接 */ public static Connection getConnection() throws SQLException { return dataSource.getConnection(); } /** * 释放资源 */ public static void close(Statement statement, Connection connection) { close(null, statement, connection); } public static void close(ResultSet resultSet, Statement statement, Connection connection) { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { e.printStackTrace(); } } if (statement != null) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } } if (connection != null) { try { connection.close();// 归还连接 } catch (SQLException e) { e.printStackTrace(); } } } /** * 获取连接池方法 */ public static DataSource getDataSource() { return dataSource; } }
LoginFrame.java
package com.sjsq.view; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.Toolkit; import java.io.IOException; import java.sql.Connection; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Timer; import java.util.TimerTask; import javax.swing.ImageIcon; 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.UIManager; import javax.swing.border.EmptyBorder; import javax.swing.SwingConstants; import com.sjsq.model.TbPerson; import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper; import com.sjsq.dao.PersonDao; import com.sjsq.tools.PwEncryption; import com.sjsq.tools.StringUtil; import com.sjsq.tools.TxtExport; /** * 登陆窗体类,为用户第一窗体 * * @author 22219 * */ public class LoginFrame extends JFrame { /** * 串行版本标识serialVersionUID */ private static final long serialVersionUID = 1L; private JPanel contentPane; public static JTextField userNameTxt; private JPasswordField passwordTxt; public static String time; public static String userId; /** * 登陆窗体类的构造函数 */ public LoginFrame() { this.setBounds(0, 0, 500, 400); this.setLocationRelativeTo(null); setResizable(false); //setIconImage(Toolkit.getDefaultToolkit().getImage(LoginFrame.class.getResource("/images/storage_128px.png"))); setTitle("登录"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel lblNewLabel = new JLabel("企业人事管理系统"); lblNewLabel.setBounds(96, 29, 300, 48); lblNewLabel.setFont(new Font("方正粗黑宋简体", Font.BOLD, 27)); lblNewLabel.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/hrm.png"))); JLabel lblNewLabel_1 = new JLabel("账号"); lblNewLabel_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 15)); lblNewLabel_1.setBounds(34, 126, 80, 18); lblNewLabel_1.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/userName.png"))); JLabel lblNewLabel_2 = new JLabel("密码"); lblNewLabel_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 15)); lblNewLabel_2.setBounds(34, 185, 65, 18); lblNewLabel_2.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/password.png"))); userNameTxt = new JTextField(); userNameTxt.setHorizontalAlignment(SwingConstants.CENTER); userNameTxt.setBounds(96, 110, 308, 46); userNameTxt.setFont(new Font("微软雅黑", Font.BOLD, 20)); userNameTxt.setToolTipText("输入用户名"); userNameTxt.setColumns(10); passwordTxt = new JPasswordField(); passwordTxt.setHorizontalAlignment(SwingConstants.CENTER); passwordTxt.setBounds(96, 169, 308, 46); passwordTxt.setFont(new Font("微软雅黑", Font.BOLD, 20)); passwordTxt.setToolTipText("输入密码"); JButton btnNewButton = new JButton("登录"); btnNewButton.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 15)); btnNewButton.setBounds(120, 252, 90, 40); this.getRootPane().setDefaultButton(btnNewButton); btnNewButton.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/login.png"))); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { loginActionPerformed(e); } }); JButton btnNewButton_1 = new JButton("重置"); btnNewButton_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 15)); btnNewButton_1.setBounds(280, 252, 90, 40); btnNewButton_1.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/reset.png"))); btnNewButton_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { resetValueActionPerformed(e); } }); JButton btnNewButton_2 = new JButton("注/改"); btnNewButton_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 15)); btnNewButton_2.setBounds(305, 252, 90, 40); btnNewButton_2.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/add.png"))); btnNewButton_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { enrollValueActionPerformed(e); } }); contentPane.add(lblNewLabel); contentPane.add(lblNewLabel_1); contentPane.add(lblNewLabel_2); contentPane.add(passwordTxt); contentPane.add(userNameTxt); contentPane.add(btnNewButton); contentPane.add(btnNewButton_1); //contentPane.add(btnNewButton_2); this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { if (JOptionPane.showConfirmDialog(null, "确认退出?", "提示", JOptionPane.YES_NO_OPTION) == 0) { System.exit(0); } } }); // bg------------------------------------------------ JLabel lbBg = new JLabel(new ImageIcon(this.getClass().getResource("/images/timg.png"))); lbBg.setBounds(0, 0, 500, 400); this.getContentPane().add(lbBg); // bg------------------------------------------------ // sj------------------------------------------------ JLabel timeLabel = new JLabel(); timeLabel.setBounds(260, 319, 220, 18); contentPane.add(timeLabel); TimerTask task = new TimerTask() { public void run() { String sdate = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()); timeLabel.setText(sdate); } }; Timer t = new Timer(); t.scheduleAtFixedRate(task, new Date(), 1000); // sj------------------------------------------------- } /** * 登陆事件处理 * * @param e */ private void loginActionPerformed(ActionEvent e) { String userName = this.userNameTxt.getText(); String password = new String(this.passwordTxt.getPassword()); if (StringUtil.isEmpty(userName)) { JOptionPane.showMessageDialog(this, "用户名不能为空!"); return; } if (StringUtil.isEmpty(password)) { JOptionPane.showMessageDialog(this, "密码不能为空!"); return; } TbPerson person = new TbPerson(userName, PwEncryption.encrypt(password, "key")); // TbPerson person = new TbPerson(userName,password); TbPerson personNew = PersonDao.login(person); if (personNew != null) { JOptionPane.showMessageDialog(this, "登陆成功!"); MainFrame mainFrame = new MainFrame(userNameTxt.getText()); mainFrame.frame.setVisible(true); // 导出登陆日志(用户id+时间) SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); time = df.format(new Date()); System.out.println("用户Id:" + userNameTxt.getText() + "\t登陆时间:" + time); try { TxtExport.creatTxtFile("Enterprise Personnel Management System"); TxtExport.writeTxtFile("员工Id:" + userNameTxt.getText() + "\t登陆时间:" + time); } catch (IOException e1) { e1.printStackTrace(); } dispose();// 销毁窗体 } else { JOptionPane.showMessageDialog(this, "用户名或密码错误!"); } } /** * 重置事件处理 * * @param e */ private void resetValueActionPerformed(ActionEvent evt) { this.userNameTxt.setText(""); this.passwordTxt.setText(""); userNameTxt.requestFocus(); } /** * 注册事件处理 * * @param e */ private void enrollValueActionPerformed(ActionEvent e) { String str = JOptionPane.showInputDialog(this, "输入超级管理员密码", "KEY", 2); TbPerson p = PersonDao.findPersonByRecordNumber("T00001"); if (str == null) { return; } else if ("".equals(str)) { JOptionPane.showMessageDialog(this, "请至少输入一个字符", "", 1); } else if (p.getPassword().equals(PwEncryption.encrypt(str, "key"))) { // }else if (str.equals(p.getPassword())) { this.setVisible(false); dispose(); EnrolmentFrame enrollFrame = new EnrolmentFrame(); enrollFrame.setVisible(true); } else { JOptionPane.showMessageDialog(this, "密码错误", "", 0); } } /** * 登陆窗口 */ public static void main(String[] args) { LoginFrame frame = new LoginFrame(); frame.setVisible(true); } }
四、其他
1.其他系统实现
Java+JSP系统系列实现
Java+JSP实现学生图书管理系统
Java+JSP实现学生信息管理系统
Java+JSP实现用户信息管理系统
Java+Servlet+JSP系统系列实现
Java+Servlet+JSP实现航空订票系统
Java+Servlet+JSP实现新闻发布系统
Java+Servlet+JSP实现图书管理系统
Java+Servlet+JSP实现停车场管理系统
Java+Servlet+JSP实现房屋租赁管理系统
Java+Servlet+JSP实现学生选课管理系统
Java+Servlet+JSP实现宠物诊所管理系统
Java+Servlet+JSP实现学生宿舍管理系统
Java+Servlet+JSP实现学生信息管理系统
Java+Servlet+JSP实现学生成绩管理系统1
Java+Servlet+JSP实现学生成绩管理系统2
Java+SSM系统系列实现
Java+SSM+JSP实现图书管理系统
Java+SSM+JSP实现宠物商城系统
Java+SSM+JSP实现超市订单系统
Java+SSM+JSP实现网上考试系统
Java+SSM+JSP实现学生成绩管理系统
Java+SSM+JSP实现学生信息管理系统
Java+SSM+Bootstrap+Maven实现网上书城系统
Java+SSM+Bootstrap+Maven实现学校教务管理系统
Java+SSH系统系列实现
Java+SSH+Bootstrap实现在线考试系统
Java+SSH+JSP实现医院在线挂号系统
Java+Springboot系统系列实现
Java+Springboot+H-ui+Maven实现营销管理系统
Java+Springboot+Bootstrap+Maven实现网上商城系统
Java+Springboot+Bootstrap+Maven实现景区旅游管理系统
JavaSwing+Mysql系统系列实现
Java+Swing实现斗地主游戏
Java+Swing实现图书管理系统
Java+Swing实现医院管理系统
Java+Swing实现考试管理系统
Java+Swing实现酒店管理系统
Java+Swing实现超市管理系统
Java+Swing实现网上订餐系统
Java+Swing实现电影购票系统
Java+Swing实现仓库管理系统1
Java+Swing实现仓库管理系统2
Java+Swing实现进销存管理系统
Java+Swing实现通讯录管理系统
Java+Swing实现停车场管理系统
Java+Swing实现员工工资管理系统
Java+Swing实现学生宿舍管理系统
Java+Swing实现学生选课管理系统
Java+Swing实现学生成绩管理系统
Java+Swing实现学校教材管理系统
Java+Swing实现学校教务管理系统
Java+Swing实现企业人事管理系统
Java+Swing实现电子相册管理系统
Java+Swing实现学生信息管理系统1
Java+Swing实现学生信息管理系统2
Java+Swing实现自助取款机(ATM)系统
JavaSwing+Txt系统系列实现
Java+Swing实现超市管理系统-TXT存储信息
Java+Swing实现宠物商店管理系统-TXT存储信息
Java+Swing实现自助取款机(ATM)系统-TXT存储信息