package frame; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.Graphics; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; import java.util.Iterator; import java.awt.Image; import java.awt.Graphics; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComboBox; 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.SwingConstants; import javax.swing.border.TitledBorder; import util.conn_db; public class Login1 extends JFrame { public Image images; ResultSet rs; String b; private JPasswordField passwordField; final JTextField TextField= new JTextField(); private JComboBox userNumComboBox; /** * Launch the application * * @param args */ // photoPath = "photo" + (i + 1) + ".jpg";// 生成文件名 // images[i] = getToolkit() // .getImage(getClass().getResource(photoPath)); // panel.setImage(images[num]); public static void main(String args[]) { try { Login1 frame = new Login1(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } /** * Create the frame */ boolean compareWithSql1(String accountT) throws Exception{ Connection ct = null; PreparedStatement pstmt = null; ResultSet rs = null; try{ //1.加载驱动 Class.forName("com.mysql.jdbc.Driver"); System.out.println("加载成功"); //2.连接数据库 //定义几个常量 String url = "jdbc:mysql://localhost:3306/keshe?characterEncoding=utf8"; String user = "root"; String passwd = "luoyiluoyi"; ct = DriverManager.getConnection(url,user,passwd); String sql; Statement stmt = ct.createStatement(); sql = "select * from teacher"; rs = stmt.executeQuery(sql); while(rs.next()){ //用户输入的信息和数据库中的信息做比较,判断输入是否正确; String acc = rs.getString(2); //String names = rs.getString(4); if(acc.equals(accountT) ){ //break; System.out.println("登录成功"); return true; } System.out.println(acc + " " ); // System.out.println(passwordT + " " +passwordT ); } // System.out.println("hahahaha"); return false; } finally{}} boolean compareWithSql(String accountT,String passwordT) throws Exception{ Connection ct = null; PreparedStatement pstmt = null; ResultSet rs = null; try{ //1.加载驱动 Class.forName("com.mysql.jdbc.Driver"); System.out.println("加载成功"); //2.连接数据库 //定义几个常量 String url = "jdbc:mysql://localhost:3306/keshe?characterEncoding=utf8"; String user = "root"; String passwd = "luoyiluoyi"; ct = DriverManager.getConnection(url,user,passwd); String sql; Statement stmt = ct.createStatement(); sql = "select * from student"; rs = stmt.executeQuery(sql); while(rs.next()){ //用户输入的信息和数据库中的信息做比较,判断输入是否正确; String acc = rs.getString(3); String names = rs.getString(4); if(acc.equals(accountT) && names.equals(passwordT)){ //break; System.out.println("登录成功"); return true; } System.out.println(acc + " " + names); System.out.println(passwordT + " " +passwordT ); } // System.out.println("hahahaha"); return false; } finally{}} public Login1() { super(); getContentPane().setLayout(new GridBagLayout()); setTitle(" 研究生科研信息管理系统 "); setResizable(false); setBounds(100, 100, 400, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JLabel softTitleLabel = new JLabel(); softTitleLabel.setFont(new Font("LUT", Font.BOLD, 22)); softTitleLabel.setBorder(new TitledBorder(null, "", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); softTitleLabel.setText("研究生科研信息管理系统"); final GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.insets = new Insets(0, 0, 20, 0); gridBagConstraints.gridy = 0; gridBagConstraints.gridx = 0; getContentPane().add(softTitleLabel, gridBagConstraints); final JPanel userNumPanel = new JPanel(); userNumPanel.setLayout(new FlowLayout()); final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints(); gridBagConstraints_1.gridy = 1; gridBagConstraints_1.gridx = 0; getContentPane().add(userNumPanel, gridBagConstraints_1); final JLabel userNumLabel = new JLabel(); userNumLabel.setVerticalTextPosition(SwingConstants.TOP); userNumLabel.setText("登录方式:"); userNumPanel.add(userNumLabel); userNumComboBox = new JComboBox(); userNumComboBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent arg0) { String username = userNumComboBox.getSelectedItem().toString() .trim(); if (username.equals("管理员登录")) { TextField.setText("Roy"); passwordField.setText("111"); } } }); userNumComboBox.setPreferredSize(new Dimension(100, 20)); userNumComboBox.addItem(" 研究生登录 "); userNumComboBox.addItem(" 导师登录 "); userNumComboBox.addItem(" 管理员登录 "); /* Iterator managerIt = dao.queryManagerOfNatural().iterator(); if (managerIt.hasNext()) { while (managerIt.hasNext()) { TbManager manager = (TbManager) managerIt.next(); StringBuffer item = new StringBuffer(" "); item.append(manager.getTbRecord().getRecordNumber()); userNumComboBox.addItem(item.toString()); } } else { userNumComboBox.addItem("TSoft"); }*/ userNumPanel.add(userNumComboBox); final JPanel userNumPanel1 = new JPanel(); userNumPanel1.setLayout(new FlowLayout()); final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints(); gridBagConstraints_5.gridy = 2; gridBagConstraints_5.gridx = 0; getContentPane().add(userNumPanel1, gridBagConstraints_5); final JLabel userNumLabel1 = new JLabel(); //userNumLabel1.setVerticalTextPosition(SwingConstants.TOP); userNumLabel1.setText("帐 户:"); TextField.setPreferredSize(new Dimension(100, 20)); userNumPanel1.add(userNumLabel1); userNumPanel1.add(TextField); getContentPane().add(userNumPanel1, gridBagConstraints_5); final JPanel passwordPanel = new JPanel(); passwordPanel.setLayout(new FlowLayout()); final GridBagConstraints gridBagConstraints_4 = new GridBagConstraints(); gridBagConstraints_4.gridy = 3; gridBagConstraints_4.gridx = 0; getContentPane().add(passwordPanel, gridBagConstraints_4); final JLabel passwordLabel = new JLabel(); passwordLabel.setText("密 码:"); passwordPanel.add(passwordLabel); passwordField = new JPasswordField(); passwordField.setPreferredSize(new Dimension(100, 20)); passwordPanel.add(passwordField); final JPanel buttonPanel = new JPanel(); final FlowLayout flowLayout = new FlowLayout(); flowLayout.setAlignment(FlowLayout.RIGHT); buttonPanel.setLayout(flowLayout); final GridBagConstraints gridBagConstraints_2 = new GridBagConstraints(); gridBagConstraints_2.ipadx = 15; gridBagConstraints_2.insets = new Insets(10, 0, 0, 0); gridBagConstraints_2.gridy = 4; gridBagConstraints_2.gridx = 0; getContentPane().add(buttonPanel, gridBagConstraints_2); // public void paint(Graphics g) { // ImageIcon icon=new ImageIcon("2.jpg"); // image=icon.getImage(); // g.drawImage(image, 0,0,null); // // TODO Auto-generated method stub // // } final JButton landButton = new JButton(); landButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String userNum = userNumComboBox.getSelectedItem().toString() .trim(); //这里是登录按钮,分别对登录进行判断,然后验证 if (userNum.equals("导师登录")) { String a=TextField.getText(); char[] passwords = passwordField.getPassword(); StringBuffer passwordBuf = new StringBuffer(); for (int i = 0; i < passwords.length; i++) { passwordBuf.append(passwords[i]); } String password = passwordBuf.toString().trim(); try { if(compareWithSql1(a)==true){ if(password.equals("111")){ new TeacherLogin(a); } else {JOptionPane.showMessageDialog(null, "帐号或者秘密不正确”!", "友情提示", JOptionPane.INFORMATION_MESSAGE); passwordField.setText("111");} }; } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println(a); System.out.println(password); } if (userNum.equals("研究生登录")) { String a=TextField.getText(); char[] passwords = passwordField.getPassword(); StringBuffer passwordBuf = new StringBuffer(); for (int i = 0; i < passwords.length; i++) { passwordBuf.append(passwords[i]); } String password = passwordBuf.toString().trim(); try { if(compareWithSql(a,password)==true){ System.out.println(a+"a..."); new StudentLogin(a); } else {JOptionPane.showMessageDialog(null, "帐号或者秘密不正确”!", "友情提示", JOptionPane.INFORMATION_MESSAGE); passwordField.setText("111");} } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println(a); System.out.println(password); //Test3 indexFrame = null; } if (userNum.equals("管理员登录")) { String a=TextField.getText(); char[] passwords = passwordField.getPassword(); StringBuffer passwordBuf = new StringBuffer(); for (int i = 0; i < passwords.length; i++) { passwordBuf.append(passwords[i]); } String password = passwordBuf.toString().trim(); System.out.println(a); System.out.println(password); //Test3 indexFrame = null; if (a.equals("Roy")){ System.out.println("yes"); if(password.equals("111")){ System.out.println("yes1"); new Manager(); } else {JOptionPane.showMessageDialog(null, "默认用户“Roy”的登录密码为“111”!", "友情提示", JOptionPane.INFORMATION_MESSAGE); passwordField.setText("111");} } } char[] passwords = passwordField.getPassword(); StringBuffer passwordBuf = new StringBuffer(); for (int i = 0; i < passwords.length; i++) { passwordBuf.append(passwords[i]); } String password = passwordBuf.toString().trim(); if (password.length() == 0) { JOptionPane.showMessageDialog(null, "请输入登录密码!", "友情提示", JOptionPane.INFORMATION_MESSAGE); return; } //IndexFrame indexFrame = null; if (userNum.equals("Roy")) { if (password.equals("111")) { //indexFrame = new IndexFrame(null); } else { JOptionPane.showMessageDialog(null, "默认用户“Roy”的登录密码为“111”!", "友情提示", JOptionPane.INFORMATION_MESSAGE); passwordField.setText("111"); return; } } else { /* TbRecord record = (TbRecord) dao.queryRecordByNum(userNum); TbManager manager = record.getTbManager(); if (password.equals(manager.getPassword())) { indexFrame = new IndexFrame(record);*/ ; } /* else { JOptionPane.showMessageDialog(null, "登录密码错误,请确认后重新输入!", "友情提示", JOptionPane.INFORMATION_MESSAGE); return; }*/ } } ); landButton.setMargin(new Insets(2, 6, 2, 6)); landButton.setText("登录"); buttonPanel.add(landButton); final JButton resetButton = new JButton(); resetButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { userNumComboBox.setSelectedIndex(0); TextField.setText(null); passwordField.setText(null); } }); resetButton.setMargin(new Insets(2, 6, 2, 6)); resetButton.setText("清空"); buttonPanel.add(resetButton); final JButton exitButton = new JButton(); exitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); exitButton.setMargin(new Insets(2, 6, 2, 6)); exitButton.setText("退出"); buttonPanel.add(exitButton); final JLabel defaultLabel = new JLabel(); defaultLabel.setText("默认管理员:Roy 默认密码:111"); final GridBagConstraints gridBagConstraints_3 = new GridBagConstraints(); gridBagConstraints_3.insets = new Insets(10, 0, 0, 0); gridBagConstraints_3.gridy = 5; gridBagConstraints_3.gridx = 0; getContentPane().add(defaultLabel, gridBagConstraints_3); // } }
最近下载更多
李朝磊 LV18
2023年11月18日
夜猫子111 LV2
2023年11月6日
fesfefe LV13
2023年9月19日
xiao小果 LV12
2022年5月24日
18692870445 LV1
2021年12月25日
qianzf LV12
2021年12月23日
尹恒yingying LV18
2021年10月12日
13112360 LV2
2021年8月27日
wodemabu88 LV1
2021年8月1日
guokai111 LV1
2021年7月22日