用户登录界面

package Student_Manage_System;import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
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;
public class UserLogin {JTextField name=new JTextField(10);JPasswordField pwd=new JPasswordField(10);public void Init() throws Exception{JFrame f=new JFrame();FlowLayout layout = new FlowLayout(FlowLayout.RIGHT,135,50);JPanel p=new JPanel(layout);JLabel label_name=new JLabel();JLabel label_pwd = new JLabel();JButton btn1=new JButton("登录");JButton btn2=new JButton("注册");JButton btn3=new JButton("取消");label_name.setText("用户名");label_pwd.setText("密码");MyClick1 mc1=new MyClick1();btn1.addMouseListener(mc1);MyClick2 mc2=new MyClick2();btn2.addMouseListener(mc2);MyClick3 mc3=new MyClick3();btn3.addMouseListener(mc3);p.add(label_name);p.add(name);p.add(label_pwd);p.add(pwd);p.add(btn1);p.add(btn2);p.add(btn3);f.add(p);f.setVisible(true);f.setSize(600,450);f.setLocation(650, 350);f.setTitle("登录界面");f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public class MyClick1 extends MouseAdapter{public void mouseClicked(MouseEvent e) {String username=name.getText();String userpwd=pwd.getText();try {Connection con=DBUtil.getCon("studentdb");String sql="select * from login_info where ID=? and Pwd=? and Job=?";PreparedStatement prep1=con.prepareStatement(sql);prep1.setString(1, username);prep1.setString(2, userpwd);prep1.setString(3, "teacher");ResultSet is_teacher=prep1.executeQuery();PreparedStatement prep2=con.prepareStatement(sql);prep2.setString(1, username);prep2.setString(2, userpwd);prep2.setString(3, "student");ResultSet is_student=prep2.executeQuery();if(is_teacher.next()){ System.out.println("老师你好,登录成功!");JOptionPane.showMessageDialog(null, "老师您好,登录成功!");Teacher tea=new Teacher();tea.init();}else if(is_student.next()){System.out.println("学生你好,登录成功!");JOptionPane.showMessageDialog(null, "登录成功!");Students stu=new Students();stu.init();}else{System.out.println("登录失败!");JOptionPane.showMessageDialog(null, "登录失败!");}con.close();} catch (Exception e1) {e1.printStackTrace();}}}public class MyClick2 extends MouseAdapter{public void mouseClicked(MouseEvent e) {try {Register r=new Register();r.init();} catch (Exception e1) {e1.printStackTrace();}}}public class MyClick3 extends MouseAdapter{public void mouseClicked(MouseEvent e) {try {JOptionPane.showMessageDialog(null, "退出成功!");System.exit(0);} catch (Exception e1) {e1.printStackTrace();}}}public static void main(String[] args) throws Exception {UserLogin login=new UserLogin();login.Init();}}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!