⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.java~161~

📁 成绩管理系统可以对学生、课程、选课、成绩的录入、班级、用户的信息进行管理等
💻 JAVA~161~
字号:
package coursedesign;

import java.awt.*;
import javax.swing.JOptionPane;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.BorderFactory;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.awt.Dimension;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Login
    extends JFrame {
  JPanel contentPane;
  XYLayout xYLayout1 = new XYLayout();
  JPanel jPanel1 = new JPanel();
  JLabel jLabel1 = new JLabel();
  XYLayout xYLayout2 = new XYLayout();
  JTextField Name_Text = new JTextField();
  JLabel jLabel2 = new JLabel();
  JPasswordField Password_Text = new JPasswordField();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JLabel jLabel3 = new JLabel();
  public Login() {
    try {
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      jbInit();
    }
    catch (Exception exception) {
      exception.printStackTrace();
    }
  }

  /**
   * Component initialization.
   *
   * @throws java.lang.Exception
   */
  private void jbInit() throws Exception {
    contentPane = (JPanel) getContentPane();
    contentPane.setLayout(xYLayout1);
    setSize(new Dimension(400, 300));
    setTitle("登陆");
    jPanel1.setBackground(UIManager.getColor(
        "InternalFrame.inactiveTitleGradient"));
    jPanel1.setBorder(BorderFactory.createLoweredBevelBorder());
    jPanel1.setLayout(xYLayout2);
    jLabel1.setText(
        "用户名:   " +
        "    " +
        "    ");
    jLabel2.setText("密  码:");
    jButton1.setText("登陆");
    jButton1.addActionListener(new Login_jButton1_actionAdapter(this));
    jButton2.setText("退出");
    jButton2.addActionListener(new Login_jButton2_actionAdapter(this));
    contentPane.setBackground(SystemColor.info);
    jPanel1.add(jLabel1, new XYConstraints(114, 20, 74, -1));
    jPanel1.add(Password_Text, new XYConstraints(200, 63, 118, -1));
    jPanel1.add(Name_Text, new XYConstraints(200, 17, 118, -1));
    jPanel1.add(jLabel2, new XYConstraints(112, 54, 56, 33));
    jPanel1.add(jButton2, new XYConstraints(239, 110, -1, -1));
    jPanel1.add(jButton1, new XYConstraints(113, 110, -1, -1));
    contentPane.add(jLabel3, new XYConstraints(0, 0, 402, 304));
    contentPane.add(jPanel1, new XYConstraints( -3, 47, 404, 180));
    Icon f =new ImageIcon("11.JPJ");
        jLabel3.setIcon(f);
  }

  public void jButton2_actionPerformed(ActionEvent e) {
    System.exit(0);
  }


  public void jButton1_actionPerformed(ActionEvent e) {
    String username=Name_Text.getText().trim();
    String password=Password_Text.getText().trim();
    if(username.equals("")||password.equals(""))
   {
   JOptionPane.showMessageDialog(null,"用户名或密码不能为空!");
   }else{
     try {
      //建立数据库连接对象
       Jdbcconn conn = new Jdbcconn();
     //连接数据库
       conn.OpenConn("student", "sa", "yaya");
       String strSQL = "select * from stu where id='" + username + "'";
       try {
     //得到记录;
         ResultSet rs = conn.getResults(strSQL);
         rs.first();
         String PassWord = rs.getString("password").toString().trim(); //得到数据库中对应用户名的密码
         int right = rs.getInt("rightlimit");
         rs.close();
         if (password.equals(PassWord)) {
           JOptionPane.showMessageDialog(null, "成功登陆!");
           dispose();
           chaxunchengji cxcj = new chaxunchengji();
           cxcj.username = username;
           Main_Frame mainFrame = new Main_Frame();
           mainFrame.users = username;
           mainFrame.setVisible(true);
           Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
           Dimension frameSize = mainFrame.getSize();
           if (frameSize.height > screenSize.height) {
             frameSize.height = screenSize.height;
           }
           if (frameSize.width > screenSize.width) {
             frameSize.width = screenSize.width;
           }
           mainFrame.setLocation( (screenSize.width - frameSize.width) / 2,
                                 (screenSize.height - frameSize.height) / 2);

           mainFrame.users = username;
            switch(right)
            {
              case 0://学生用户

                mainFrame.jMenuItem4.setVisible(false);
                mainFrame.jMenuItem6.setVisible(false);
                mainFrame.jMenuItem1.setVisible(false);
                mainFrame.jMenuItem3.setVisible(false);
                break;
              case 1://教师用户
                mainFrame.jMenuItem3.setVisible(false);
                mainFrame.jMenuItem6.setVisible(false);
                break;
              default://管理员用户
                mainFrame.setTitle("学生成绩管理系统");
                break;
            }
         }
         else {
           JOptionPane.showMessageDialog(null, "密码错误,请重输!");
           Password_Text.setText("");
         }
       }
       catch (Exception ex) {
         JOptionPane.showMessageDialog(null, "用户名或密码错误1!");
         Name_Text.setText("");
         Password_Text.setText("");
       }
       conn.closeConn(); //关闭数据库连接
       } catch (Exception ex) {
         JOptionPane.showMessageDialog(null, "用户名或密码错误2!!");
         System.out.print(ex.getMessage());
     }//first try catch
   }  //second try catch
    }//end else


}//end method

class Login_jButton1_actionAdapter
    implements ActionListener {
  private Login adaptee;
  Login_jButton1_actionAdapter(Login adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

class Login_jButton2_actionAdapter
    implements ActionListener {
  private Login adaptee;
  Login_jButton2_actionAdapter(Login adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -