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

📄 login.java~68~

📁 学生信息管理系统,包括成绩查询,成绩排序,用ACCESS做数据库连接
💻 JAVA~68~
字号:
package Chapter1;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Rectangle;
import java.sql.*;

public class Login  extends JFrame implements ActionListener
{
  public static final int WIDTH=400;
  public static final int HEIGHT=400;
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  //test
  public static String ID,password;
  public static JTextField jTextField1= new JTextField();

  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JLabel jLabel3 = new JLabel();
  static JPasswordField jPasswordField1 = new JPasswordField();
  static JComboBox jComboBox1 = new JComboBox();
  public Login()
  {
    setSize(WIDTH,HEIGHT);
    setTitle("学生信息管理系统");
    Container contentPane=getContentPane();
    contentPane.setBackground(Color.green);
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
  public void actionPerformed(ActionEvent e)
  {
    if(e.getActionCommand().equals("登录"))
   {
       try
       {
         String url = "jdbc:odbc:MySecondAccess";
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection con = DriverManager.getConnection(url, "", "");
         Statement stmt = con.createStatement();
         String SQLOrder1="SELECT * FROM ManagersInformation WHERE 帐号='"+jTextField1.getText()+"' AND 密码='"+jPasswordField1.getText()+"'";
         String SQLOrder2="SELECT * FROM StudentsInformation WHERE 帐号='"+jTextField1.getText()+"' AND 密码='"+jPasswordField1.getText()+"'";
          ResultSet resultset=null;
          if(jComboBox1.getSelectedIndex()==0)
                resultset= stmt.executeQuery(SQLOrder1);
          else if(jComboBox1.getSelectedIndex()==1)
                resultset= stmt.executeQuery(SQLOrder2);

          ID=jTextField1.getText().trim();
          password=jPasswordField1.getText();
          if (resultset.next())
          {
            this.dispose();
            ManagerInterface n1= new ManagerInterface();
            StudentInterface n2=new StudentInterface();
             if(jComboBox1.getSelectedIndex()==0)
                  {  n1.setVisible(true);  n2.dispose();}
             else if(jComboBox1.getSelectedIndex()==1)
                  {  n2.setVisible(true);  n1.dispose(); }
          }
          else
          {
            JOptionPane.showMessageDialog(null, "您输入的帐号或密码不正确,请重新输入!",
                                          "张呈刚提醒您.....",
                                          JOptionPane.WARNING_MESSAGE);
            jTextField1.setText("");
            jPasswordField1.setText(""); //弹出警告提示框并把已输入的帐号和密码清除,以让用户重新输入
          }
            jPasswordField1.setText("");
         stmt.close();
         con.close();
       }
     catch(Exception ex)
       {
            JOptionPane.showMessageDialog(null,ex.getMessage(),"警告信息",JOptionPane.WARNING_MESSAGE);
            JOptionPane.showMessageDialog(null,ex.getStackTrace(),"警告信息",JOptionPane.WARNING_MESSAGE);
       }
  }
     else if (e.getActionCommand().equals("退出系统"))
    {
           System.exit(0);
    }
  }
  public static void main(String[] args)
  {
      Login n=new Login();
      n.setVisible(true);
  }
  private void jbInit() throws Exception
  {
    jLabel1.setText("帐号: ");
    jLabel1.setBounds(new Rectangle(76, 113, 60, 27));
    this.getContentPane().setLayout(null);
    jLabel2.setText("口令:");
    jLabel2.setBounds(new Rectangle(75, 170, 59, 32));
    jTextField1.setText("");
    jTextField1.setBounds(new Rectangle(135, 116, 87, 23));
    jButton1.setBounds(new Rectangle(59, 232, 99, 33));
    jButton1.setText("登录");
//    if(jTextField1.getText().equals("")&&jPasswordField1.getText().equals(""))
//           jButton1.setEnabled(false);
    jButton2.setBounds(new Rectangle(213, 231, 98, 34));
    jButton2.setText("退出系统");
    jLabel3.setText("请选择用户类型:");
    jLabel3.setBounds(new Rectangle(35, 60, 116, 28));
    jPasswordField1.setBounds(new Rectangle(135, 172, 87, 23));
    jComboBox1.setBounds(new Rectangle(134, 62, 89, 25));
    if((jComboBox1.countComponents()==2))
    {
      jComboBox1.addItem("管理员");
      jComboBox1.addItem("学生");
    }
    this.getContentPane().add(jLabel1, null);
    this.getContentPane().add(jLabel2, null);
    this.getContentPane().add(jTextField1, null);
    this.getContentPane().add(jButton1, null);
    this.getContentPane().add(jButton2, null);
    this.getContentPane().add(jPasswordField1, null);
    this.getContentPane().add(jComboBox1);
    this.getContentPane().add(jLabel3, null);
    jComboBox1.addActionListener(this);
    jButton1.addActionListener(this);
    jButton2.addActionListener(this);
  }
}

⌨️ 快捷键说明

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