java系统登录_JAVA--图书管理员登陆系统

1 packagecom.shine.view;2

3 importjava.awt.EventQueue;4 importjava.awt.Font;5 importjava.awt.event.ActionEvent;6 importjava.awt.event.ActionListener;7 importjava.sql.Connection;8

9 importjavax.swing.GroupLayout;10 importjavax.swing.GroupLayout.Alignment;11 importjavax.swing.ImageIcon;12 importjavax.swing.JButton;13 importjavax.swing.JFrame;14 importjavax.swing.JLabel;15 importjavax.swing.JOptionPane;16 importjavax.swing.JPanel;17 importjavax.swing.JPasswordField;18 importjavax.swing.JTextField;19 importjavax.swing.border.EmptyBorder;20

21 importcom.shine.dao.UserDao;22 importcom.shine.model.User;23 importcom.shine.util.Db_util;24 importcom.shine.util.Stringutil;25

26 public class logOn extendsJFrame {27

28 private Db_util dbutil=newDb_util();29 private UserDao userDao=newUserDao();30 privateJPanel contentPane;31 privateJTextField userNameTxt;32 privateJPasswordField PasswordTxt;33

34 /**

35 * Launch the application.36 */

37 public static voidmain(String[] args) {38 EventQueue.invokeLater(newRunnable() {39 public voidrun() {40 try{41 logOn frame = newlogOn();42 frame.setVisible(true);43 } catch(Exception e) {44 e.printStackTrace();45 }46 }47 });48 }49

50 /**

51 * Create the frame.52 */

53 publiclogOn() {54 setResizable(false);55 setTitle("\u7BA1\u7406\u5458\u767B\u9646");56 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);57 setBounds(100, 100, 665, 532);58 contentPane = newJPanel();59 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));60 setContentPane(contentPane);61

62 JLabel lblNewLabel = new JLabel("\u56FE\u4E66\u7BA1\u7406\u7CFB\u7EDF");63 lblNewLabel.setFont(new Font("宋体", Font.BOLD, 22));64 lblNewLabel.setIcon(new ImageIcon(logOn.class.getResource("/imags/558952.gif")));65

66 JLabel lblNewLabel_1 = new JLabel("\u7528\u6237\u540D");67 lblNewLabel_1.setIcon(new ImageIcon(logOn.class.getResource("/imags/userName.png")));68 lblNewLabel_1.setFont(new Font("宋体", Font.BOLD, 20));69

70 JLabel lblNewLabel_2 = new JLabel("\u5BC6 \u7801");71 lblNewLabel_2.setIcon(new ImageIcon(logOn.class.getResource("/imags/password.png")));72 lblNewLabel_2.setFont(new Font("宋体", Font.BOLD, 20));73

74 userNameTxt = newJTextField();75 userNameTxt.setColumns(10);76

77 PasswordTxt = newJPasswordField();78

79 JButton btnNewButton = new JButton("\u767B \u9646");80 btnNewButton.addActionListener(newActionListener() {81 public voidactionPerformed(ActionEvent e) {82 logInActionperformed(e);83 }84 });85 btnNewButton.setIcon(new ImageIcon(logOn.class.getResource("/imags/login.png")));86 btnNewButton.setFont(new Font("宋体", Font.BOLD, 18));87

88 JButton button = new JButton("\u91CD \u7F6E");89 button.addActionListener(newActionListener() {90 public voidactionPerformed(ActionEvent e) {91 resetValueActionperformed(e);92 }93 });94 button.setIcon(new ImageIcon(logOn.class.getResource("/imags/reset.png")));95 button.setFont(new Font("宋体", Font.BOLD, 18));96 GroupLayout gl_contentPane = newGroupLayout(contentPane);97 gl_contentPane.setHorizontalGroup(98 gl_contentPane.createParallelGroup(Alignment.LEADING)99 .addGroup(gl_contentPane.createSequentialGroup()100 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)101 .addGroup(gl_contentPane.createSequentialGroup()102 .addGap(163)103 .addComponent(lblNewLabel))104 .addGroup(gl_contentPane.createSequentialGroup()105 .addGap(101)106 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)107 .addGroup(gl_contentPane.createSequentialGroup()108 .addComponent(lblNewLabel_1)109 .addGap(19))110 .addGroup(gl_contentPane.createSequentialGroup()111 .addComponent(lblNewLabel_2)112 .addGap(18)))113 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)114 .addComponent(userNameTxt, GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)115 .addComponent(PasswordTxt, GroupLayout.PREFERRED_SIZE, 267, GroupLayout.PREFERRED_SIZE)))116 .addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()117 .addContainerGap()118 .addComponent(btnNewButton)119 .addGap(94)120 .addComponent(button, GroupLayout.PREFERRED_SIZE, 110, GroupLayout.PREFERRED_SIZE)))121 .addGap(179))122 );123 gl_contentPane.setVerticalGroup(124 gl_contentPane.createParallelGroup(Alignment.LEADING)125 .addGroup(gl_contentPane.createSequentialGroup()126 .addGap(35)127 .addComponent(lblNewLabel)128 .addGap(54)129 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)130 .addComponent(lblNewLabel_1)131 .addComponent(userNameTxt, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE))132 .addGap(47)133 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)134 .addComponent(lblNewLabel_2)135 .addComponent(PasswordTxt, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE))136 .addGap(68)137 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)138 .addComponent(button, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)139 .addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))140 .addContainerGap(95, Short.MAX_VALUE))141 );142 contentPane.setLayout(gl_contentPane);143 }144 /**

145 * 登陆事件146 *@parame147 */

148 private voidlogInActionperformed(ActionEvent e) {149 String userName=this.userNameTxt.getText();150 String Password=new String(this.PasswordTxt.getPassword());151 if(Stringutil.isEmpty(userName)){152 JOptionPane.showMessageDialog(null, "用户名不可为空");153 return;154

155 }156 if(Stringutil.isEmpty(Password)){157 JOptionPane.showMessageDialog(null, "密码不可为空");158 return;159 }160 User user=newUser(userName,Password);161 Connection con=null;162 try{163 con=dbutil.getCon();164 User currentUser=userDao.login(con, user);165 if(currentUser!=null){166 JOptionPane.showMessageDialog(null, "登陆成功");167

168 }else{169 JOptionPane.showMessageDialog(null, "用户名或密码错误!");170 }171 } catch(Exception e1) {172 //TODO 自动生成的 catch 块

173 e1.printStackTrace();174 }175 }176

177 /**

178 * 重置事件处理179 *@parame180 */

181 protected voidresetValueActionperformed(ActionEvent evt) {182 this.userNameTxt.setText("");183 this.PasswordTxt.setText("");184 }185 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值