swing + spring3 + hibernate4 框架 源码+数据库

  • e3_445044
    了解作者
  • 9.8MB
    文件大小
  • 7z
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-14 13:28
    上传日期
swing + spring3 + hibernate4 框架 源码+数据库 ,目前网上应该都是hibernate3,我自己整了一个,用的是hibernate4,建议使用这个, 以前的版本控制还是比较繁琐
TestSwing.7z
内容介绍
package com.baxt.dao; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Image; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; 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 org.jboss.logging.Logger; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.baxt.action.AdminAction; public class Login extends JFrame { /** * */ private static final long serialVersionUID = 8244981158714556226L; private static Logger loger=Logger.getLogger(Login.class);//打印日志 private JButton esc = new JButton("取消"); private JLabel username = new JLabel("账号"); private JLabel password = new JLabel("密码"); private JTextField textusername = new JTextField(10); private JPasswordField textpassword = new JPasswordField(10); private JButton ok = new JButton("确定"); private static String userStr; private static String passStr; public static Connection con = null; public PreparedStatement stat = null; public ResultSet rs = null; public Login() { this.setTitle("登录系统"); this.setVisible(true); this.setSize(200, 100); JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); JPanel panel3 = new JPanel(); panel1.add(username); panel1.add(textusername); textpassword.setEchoChar('●'); panel2.add(password); panel2.add(textpassword); panel3.add(ok); panel3.add(esc); this.add(panel1, BorderLayout.NORTH); this.add(panel2, BorderLayout.CENTER); this.add(panel3, BorderLayout.SOUTH); Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); int screeWidth = (int) screenSize.getWidth(); int screeHeight = (int) screenSize.getHeight(); this.setLocation(screeWidth / 3, screeHeight / 4); this.setResizable(false); this.pack(); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 退出事件 esc.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // 参数为1表示非正常退出,为0则表示正常退出 System.exit(1); } }); // 登录事件 ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub userStr=textusername.getText(); passStr= new String(textpassword.getPassword()); ApplicationContext ac=new ClassPathXmlApplicationContext("classpath:/com/baxt/config/applicationContext.xml"); AdminAction aa=(AdminAction) ac.getBean("adminAction"); try { aa.go(userStr, passStr); loger.info("==============登录成功"+userStr); JOptionPane.showMessageDialog(null,"登陆成功","提示",JOptionPane.INFORMATION_MESSAGE); } catch (Exception e1) { if(Eo.eo==1){ loger.info("====================登录失败,账号错误"); JOptionPane.showMessageDialog(null,"您的账号有误","提示",JOptionPane.WARNING_MESSAGE); }else if(Eo.eo==2){ loger.info("====================登录失败,密码错误"); JOptionPane.showMessageDialog(null,"您的密码有误","提示",JOptionPane.WARNING_MESSAGE); }else if(Eo.eo==3){ loger.info("====================登录失败,账号错误"); JOptionPane.showMessageDialog(null,"账号不能为空","提示",JOptionPane.WARNING_MESSAGE); }else if(Eo.eo==4){ loger.info("====================登录失败,密码错误"); JOptionPane.showMessageDialog(null,"密码不能为空","提示",JOptionPane.WARNING_MESSAGE); } e1.printStackTrace(); } } // @Override // public void actionPerformed(ActionEvent e) { // userStr = textusername.getText(); // passStr = new String(textpassword.getPassword()); // if("".equals(userStr)){ // JOptionPane.showMessageDialog(null,"账号不能为空!","提示",JOptionPane.WARNING_MESSAGE); // return; // }else if("".equals(passStr)){ // JOptionPane.showMessageDialog(null,"密码不能为空!","提示!",JOptionPane.WARNING_MESSAGE); // return; // } // String sql = "select * from user where username = ?"; // // 加载数据库 // // 获取配置文件 // // Properties pre=new Properties(); // // ClassLoader loader=Login.class.getClassLoader(); // // InputStream instream // // =loader.getResourceAsStream("db.properties"); // try { // System.out.println("账号为:" + userStr); // System.out.println("密码为:"+passStr); // // pre.load(instream); // // String driverClass=pre.getProperty("driverClass"); // // String url=pre.getProperty("url"); // // String username=pre.getProperty("username"); // // String password=pre.getProperty("password"); // // Class.forName(driverClass); // // con=DriverManager.getConnection(url,username,password); // con = OpenSQL.openCon(); // stat = con.prepareStatement(sql); // stat.setString(1, userStr); // rs = stat.executeQuery(); // boolean b = rs.next(); // if (b) { // if ((rs.getString("username")).equals(userStr)) { // if ((rs.getString("password")).equals(passStr)) { // JOptionPane.showMessageDialog(null, "登录成功", // "提示", JOptionPane.INFORMATION_MESSAGE); // System.exit(0); // } else { // textpassword.setText(""); // JOptionPane.showMessageDialog(null, // "密码错误!登录失败!", "提示", // JOptionPane.WARNING_MESSAGE); // } // } // } else { // textusername.setText(""); // textpassword.setText(""); // JOptionPane.showMessageDialog(null, "账号不存在!登录失败!", // "提示", JOptionPane.WARNING_MESSAGE); // } // // if(){ // // JOptionPane.showMessageDialog(null,"登录成功","提示",JOptionPane.INFORMATION_MESSAGE); // // }else{ // // JOptionPane.showMessageDialog(null,"登录失败", // // "提示",JOptionPane.INFORMATION_MESSAGE); // // } // } catch (Exception e1) { // e1.printStackTrace(); // } finally { // OpenSQL.closeCon(con); // } // } }); } public static void main(String[] args) { new Login(); } }
评论
    相关推荐