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

📄 login.java

📁 一个毕业设计的Java学生成绩管理系统
💻 JAVA
字号:
package scoremis;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class login extends JFrame
{
	JPanel contentPane;                  // 初始化登录界面的各种组件
    JLabel jLabel1=new JLabel("用户名");
    JTextField uname=new JTextField();
    JLabel jLabel2=new JLabel("密码");
    JPasswordField upsd=new JPasswordField();
    JButton submit=new JButton("登录");
    JButton cancel=new JButton("取消");
    JLabel jLabel3=new JLabel("学生成绩管理系统");
    JLabel jLabel4=new JLabel("身份");
    JComboBox identity=new JComboBox();
    public login(){
    	try{
    		setDefaultCloseOperation(EXIT_ON_CLOSE);//设置窗口的关闭按钮的功能
    		jbInit();
    	}catch(Exception exception){exception.printStackTrace();    	}
    	
    }
    private void jbInit()throw Exception
    { //用于设置窗口各组件的可见性大小及组件的位置
    	contentPane=(JPanel)getContentPane();
    	contentPane.setLayout(null);
    	setSize(new Dimension(300,350));
    	setResizable(false);
    	setTitle("学生成绩管理系统");
    	jLabel3.setLocation(70,30);
    	jLabel3.setVisible(true);
    	jLabel3.setSize(200,50);
    	jLabel1.setLocation(50,90);
    	jLabel1.setVisible(true);
    	jLabel1.setSize(50,40);
    	uname.setSize(60,40);
    	uname.setLocation(110,90);
    	uname.setVisible(true);
    	jLabel2.setLocation(50,140);
    	jLabel2.setSize(60,40);
    	jLabel2.setVisible(true);
    	upsd.setLocation(110,140);
    	upsd.setVisible(true);
    	upsd.setSize(80,40);
    	jLabel4.setLocation(50,190);
    	jLabel4.setVisible(true);
    	jLabel4.setSize(50,40);
    	identity.setLocation(110,190);
    	identity.setVisible(true);
    	identity.setSize(60,40);
    	identity.addItem(new String("学生"));
    	identity.addItem(new String("教师"));
    	identity.addItem(new String("管理员"));
    	submit.setVisible(true);
    	submit.setLocation(50,240);
    	submit.setSize(50,40);
    	cancel.setVisible(true);
    	cancel.setLocation(150,240);
    	cancel.setSize(50,40);
    	contentPane.add(jLabel3);//添加各个组件
    	contentPane.add(jLabel1);
    	contentPane.add(uname);
    	contentPane.add(jLabel2);
    	contentPane.add(upsd);
    	contentPane.add(jLabel4);
    	contentPane.add(identity);
    	contentPane.add(submit);
    	contentPane.add(cancel);
    
    	submit.addActionListener(new yanzheng());//为取消和登录按钮添加监视器
    	cancel.addActionListener(new yanzheng());	
    	
    }
    class yanzheng implements ActionListener
    {
    	public void actionPerformed(ActionEvent e){
    		if(e.getScouce()==submit)
    		{
    			String xm=uname.getText();
    			String mm=new String(upsd.getPassword());
    			String sf=(String)identity.getSelectedItem();
    			dbconn db=new dbconn();
    			ResultSet rs=null;
    			String sql="";
    			boolean login=false;
    			if(sf.equals("学生"))
    			sql="select * from student where name='"+xm+"' and ID='"+mm+"'";
    			else if(sf.equals("管理员"))
    			sql="select * from teacher where name='"+xm+"' and psd='"+mm+"' and isAdmin=true";
    			else
    			sql="select * from teacher where name='"+xm+"' and psd='"+mm+"'";
    			try   //执行相应的sql语句如果存在相应的记录则登录成功,否则弹出错误的信息对话框
    			{
    				rs=db.Query(sql);
    				if(rs.next())
    				{
    					login=true;
    				}
    				else
    				{
    					JOptionPane.showMessageDialog(null,"用户/密码错误,请重新输入!");
    					
    				}
    				if(login==true)//根据登录身份的不同设置主窗口中各个模块的可用性
    			{
    				if(sf.equals("学生"))
    				{
    					MainUI mui=new MainUI(xm,mm,sf);
    					mui.scopy.setEnabled(false);
    					mui.sback.setEnabled(false);
    					mui.sdayamin.setEnabled(false);
    					mui.ptec.setEnabled(false);
    					mui.cou.setEnabled(false);
    					mui.sinput.setEnabled(false);
    					mui.clogin.setEnabled(false);
    					mui.sedit.setEnablec(false);
    					mui.setVisible(true);
    				}
    				else if(sf.equals("管理员")){
    					MainUI admin=new MainUI(xm,mm,sf);
    					admin.sedit.setEnabled(false);
    					admin.sinput.setEnabled(false);
    					setVisibled(true);
    					
    				}
    				else if(sf.equals("教师")){
    					rs=db.Query("select * from quanxian");
    					if(rs.next())
    					{
    						MainUI teac=new MainUI(xm,mm,sf);
    						teac.scopy.setEnabled(false);
    						teac.sback.setEnabled(false);
    						teac.sdayadmin.setEnabled(false);
    						teac.cou.setEnablec(false);
    						teac.sinput.setEnabled(rs.getBoolean(1));
    						teac.sedit.setEnabled(rs.getBoolean(2));
    						teac.pstu.setEnabled(rs.getBoolean(3));
    						teac.ptec.setEnabled(rs.getBoolean(4));
    						setVisible(false);
    						teac.setVisible(true);
    					}
    				}
    				
    			}
    				
    			}
    			
    			catch(Exception er)
    			{
    				System.out.println(er.toString());
    			}
    		}
    	}
    	
    }
}

⌨️ 快捷键说明

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