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

📄 userlogin.java

📁 学生成绩管理系统,可以修改
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;

public  class UserLogin extends JFrame implements ActionListener {
	  DataBaseManager db=new DataBaseManager();
	  JButton jButton2;
	  ResultSet rs;
	  JRadioButton jRadioButton4;
	 JLabel jLabel5;
	  JLabel jLabel4;
	  JLabel jLabel2,jLabel3;
	  JRadioButton jRadioButton3;
	  JRadioButton jRadioButton2;
	  JRadioButton jRadioButton1;
	  JButton jButton3;
	  JButton jButton1;
	  JLabel jLabel1;
	  JTextField jTextField1;
	  JPasswordField jPasswordField1;
  public UserLogin(){
        	   this.setBounds(431, 223, 356, 225);
        	   this.setLayout(null);
        	   this.setTitle("用户登陆");
        	   this.setResizable(false); //固定窗口大小
        	   this.setVisible(true); //显示面板
        	 {
        		 jLabel2 = new JLabel();
        		 getContentPane().add(jLabel2);//获得窗口的面板,用来添加内容
        		 jLabel2.setText("用户名:");
        		 jLabel2.setBounds(56, 56, 49, 15);
        	 }
        	 {
        		 jTextField1 = new JTextField();
        		 getContentPane().add(jTextField1);
        		 jTextField1.setText("");
        		 jTextField1.addActionListener(this);
        		 jTextField1.setBounds(102, 51, 150, 24);
        		 jTextField1.grabFocus(); //显示用户文本框的光标
        	 }
        	 {
        		 jLabel3 = new JLabel();
        		 getContentPane().add(jLabel3);
        		 jLabel3.setText("密码:");
        		 jLabel3.setBounds(62, 91, 41, 15);
        	 }
        	 {
        		 jPasswordField1 = new JPasswordField();
        		 getContentPane().add(jPasswordField1);
        		 jPasswordField1.setText("");
        		 jPasswordField1.addActionListener(this);
        	     jPasswordField1.setEchoChar('*'); //设置输入用户密码为
        		 jPasswordField1.setBounds(102, 87, 150, 22);
        	 }        	
        	 {
        		 jButton2 = new JButton();
        		 jButton2.addActionListener(this);
        		 getContentPane().add(jButton2);
        		 jButton2.setForeground(Color.RED);
        		 jButton2.setText("取消");
        		 jButton2.setBounds(136, 148, 62, 22);
        	 }
        	 {
        		 jLabel1 = new JLabel();
        		 getContentPane().add(jLabel1);
        		 jLabel1.setText("jLabel1");
        		 jLabel1.setIcon(new ImageIcon(getClass().getClassLoader().getResource("logina.jpg")));
        		 jLabel1.setBounds(-6, -14, 363, 80);
        	 }
        	 {
        		 jButton1 = new JButton();
        		 getContentPane().add(jButton1);
        		 jButton1.addActionListener(this);
        		 jButton1.setText("jButton1");
        		 jButton1.setBounds(61, 148, 48, 22);
        		 jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource("登录.gif")));
        	 }
        	 {
        		 jButton3 = new JButton();
        		 getContentPane().add(jButton3);
        		 jButton3.addActionListener(this);
        		 jButton3.setText("注册");
        		 jButton3.setBounds(226, 148, 48, 22);
        		 jButton3.setIcon(new ImageIcon(getClass().getClassLoader().getResource("注册5.gif")));
        	 }
        	 {
        		 jRadioButton1 = new JRadioButton();
        		 getContentPane().add(jRadioButton1);
        		 jRadioButton1.setText("系统管理员");
        		 jRadioButton1.addActionListener(this);
        		 jRadioButton1.setBounds(25, 117, 95, 19);
        	 }
        	 {
        		 jRadioButton2 = new JRadioButton();
        		 getContentPane().add(jRadioButton2);
        		 jRadioButton2.setText("统计员");
        		 jRadioButton2.addActionListener(this);
        		 jRadioButton2.setBounds(120, 117, 67, 18);
        		 
        	 }
        	 {
        		 jRadioButton3 = new JRadioButton();
        		 getContentPane().add(jRadioButton3);
        		 jRadioButton3.setText("录入员");
        		 jRadioButton3.addActionListener(this);
        		 jRadioButton3.setBounds(193, 117, 65, 19);
        	 }
        	 {
        		 jRadioButton4 = new JRadioButton();
        		 getContentPane().add(jRadioButton4);
        		 jRadioButton4.setText("学生");
        		 jRadioButton4.addActionListener(this);
        		 jRadioButton4.setBounds(270, 117, 60, 19);
        	 }
        	 ButtonGroup group = new ButtonGroup();
     	      group.add(jRadioButton1);
     	      group.add(jRadioButton2); 
     	      group.add(jRadioButton3); //把单选框按钮放在同一个组按钮中
     	      group.add(jRadioButton4); 
        	 {
        		 jLabel4 = new JLabel();
        		 getContentPane().add(jLabel4);
        		 jLabel4.setText("jLabel4");
        		 jLabel4.setBounds(-372, 228, 1326, 473);
        		 jLabel4.setIcon(new ImageIcon(getClass().getClassLoader().getResource("mww.jpg")));
        	 }
        	 {
        		 jLabel5 = new JLabel();
        		 getContentPane().add(jLabel5);
        		 jLabel5.setText("jLabel5");
        		 jLabel5.setIcon(new ImageIcon(getClass().getClassLoader().getResource("mww.jpg")));
        		 jLabel5.setBounds(-41, 60, 1326, 700);
        	 }
        }
public void actionPerformed(ActionEvent e)
{
	if(e.getSource()==jButton2)
	 {
	    System.exit(0);
	 }
	if(e.getSource()==jButton3){
		  int result=JOptionPane.showOptionDialog(null, "是否要注册新用户?", "系统提示", 
		  JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
		 null, new String[] {"是","否"}, "否");   //弹出相应消息对话框
	           if(result==JOptionPane.YES_OPTION){   
			        new UserRegrster();
			        this.dispose();
	           }
	     else{
		            new UserLogin();
		            this.dispose();
	         }
	   }
   else
	{  
      if(e.getSource()==jButton1){
	          if(jTextField1.getText().trim().equals(""))
		         {
	    	  JOptionPane.showOptionDialog(this,"用户不能为空", "错误信息" , 
	    	  JOptionPane.DEFAULT_OPTION,  JOptionPane.ERROR_MESSAGE, 
	    	  null, null, null);  //弹出相应消息对话框
	    	  jTextField1.requestFocus();//焦点放置在用户名文本框中
			     return;
		       }
		  if(jPasswordField1.getText().trim().equals(""))
		     {
            JOptionPane.showOptionDialog(this,"密码不能为空", "错误信息" ,
    		JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, 
    		null, null, null);  //弹出相应消息对话框
            jPasswordField1.requestFocus();//焦点放置在密码文本框中
			  return;
		    }
		String strSQL;
 //SQL语句根据用户名和密码获得结果集 
		strSQL="select * from [user1] where UserName='"+
		  jTextField1.getText().trim()+"'and PassWord='"+
		  jPasswordField1.getText().trim()+"'";
		 rs=db.getResult(strSQL);
		 boolean isExist=false;
	try
		{
			if(isExist=rs.first()) {
			        if(jRadioButton1.getText().equals("系统管理员")){
			            new Administrator();
			            this.setExtendedState(Administrator.MAXIMIZED_BOTH); //显示最大的窗口界面
			            this.dispose(); //自动消失
			      }
			        else if(jRadioButton2.getText().equals("统计员")) {
			    	    new Statistician();
					    this.setExtendedState(Administrator.MAXIMIZED_BOTH);
					    this.dispose();
			      }
			        else if(jRadioButton3.getText().equals("录入员")){
			    	    new Inputer();
					    this.setExtendedState(Administrator.MAXIMIZED_BOTH);
					    this.dispose();
			      }
			        else if(jRadioButton1.getText().equals("学生")){
			    	    new Students();
					    this.setExtendedState(Administrator.MAXIMIZED_BOTH);
					    this.dispose();
		          }
	      }	
		}
   catch(SQLException sqle)
		{
			System.out.println(sqle.toString());
		 }
		 if(!isExist)
		 {
			  JOptionPane.showOptionDialog(this,"用户名不存在或者密码不正确!", "错误信息" ,
			  JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, 
			  null, null, null); //弹出相应消息对话框
			  jTextField1.setText(null);//将用户文本框置为空
			  jPasswordField1.setText(null);//将密码文本框置为空
			  jTextField1.requestFocus();//焦点放置在用户名文本框中
		  }
		 }
	  }
	}
public static void main(String[] args) {
	   new UserLogin();
	}
}

⌨️ 快捷键说明

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