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

📄 studentlogin.java

📁 用Java与MySQL开发的小型学生成绩管理系统
💻 JAVA
字号:
package chuangti;
import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import login.*;
public class studentlogin extends JFrame{
	JTextField text1=new JTextField("",6);
    JTextField text2=new JTextField("",6);
    JTextField text4=new JTextField("",6);
    String password=new String();
    String xuehao=new String();
    String usersName=new String();
    int i=0;
public studentlogin()
{   
	JPanel username=new JPanel();
	JPanel passWord=new JPanel();
	JPanel number=new JPanel();
	JPanel login=new JPanel();
	JLabel label1=new JLabel("学生姓名:");
	JLabel hao=new JLabel("学生学号:");
	JLabel label2=new JLabel("用户密码:");
	setLayout(new GridLayout(4,1,10,10));
	username.setLayout(new FlowLayout());
	username.add(label1);
	username.add(text1);
	number.add(hao);
	number.add(text4);
	passWord.setLayout(new FlowLayout());
	passWord.add(label2);
	passWord.add(text2);
	JButton nowlogin=new JButton("登录");
	login.add(nowlogin);
	add(number);
	add(username);
	add(passWord);
	add(login);
	nowlogin.addActionListener(new B());
}
public String[] chaxun(String x,String y)
{  
	ResultSet rs=null,b=null;
	String[] a=new String[4];
	
try
	{DBConnection dbConn = new DBConnection();
	Connection conn = DBConnection.getConncetion();
	PreparedStatement checkUser = conn.prepareStatement("SELECT * FROM jiben WHERE xingming=? and xuehao=?");
   checkUser.setString(1,x);
   checkUser.setString(2, y);
  rs = checkUser.executeQuery();
  if(rs.next()) 
	  {a[0]=rs.getString(1);
	  a[1]=rs.getString(2);
	  a[2]=rs.getString(3);
	  a[3]=rs.getString(4);
	  }
	}
catch(Exception e)
{
	e.printStackTrace();
}
finally
{if(rs!=null)
{try
	{ rs.close();
		}
	catch(SQLException e){}
	rs=null;
}
}
	return a;
}
public String[][] chaxun1(String x)
{  
	ResultSet rs=null,b=null;
	String[][] a=new String[10][2];
try
	{DBConnection dbConn = new DBConnection();
	Connection conn = DBConnection.getConncetion();
	PreparedStatement checkUser = conn.prepareStatement("SELECT kecheng,chengji FROM fen,ke,jiben WHERE jiben.xuehao=? AND  jiben.xuehao=fen.xuehao AND ke.kechenghao=fen.kechenghao");
    checkUser.setString(1, x);
	rs = checkUser.executeQuery();
  
	while(rs.next()) 
     { 
	  a[i][0]=rs.getString(1);
	  a[i][1]=rs.getString(2);
	  i++;}
     }

catch(Exception e)
{
	e.printStackTrace();
   
}
finally
{if(rs!=null)
{try
	{ rs.close();
		}
	catch(SQLException e){}
	rs=null;
}
}
	return a;
}

class change extends JFrame {
	private JLabel a=new JLabel("旧密码:");
	private JTextField a1=new JTextField("",6);
	private JLabel b=new JLabel("新密码:");
	private JTextField b1=new JTextField("",6);
	private JLabel c=new JLabel("确认新密码:");
	private JTextField c1=new JTextField("",6);
	JButton d=new JButton("确定");
	JButton e=new JButton("取消");
	public change()
	{
		JPanel f=new JPanel(new FlowLayout());
		JPanel g=new JPanel(new FlowLayout());
		JPanel h=new JPanel(new FlowLayout());
		JPanel i=new JPanel(new FlowLayout());
	    setLayout(new GridLayout(4,2));
	    f.add(a);
        f.add(a1);
        g.add(b);
        g.add(b1);
        h.add(c);
        h.add(c1);
        i.add(d);
        i.add(e);
        add(f);
        add(g);
        add(h);
        add(i);
    d.addActionListener(new ActionListener()
    {
    	public void actionPerformed(ActionEvent e)
    	{
    		String a2=a1.getText();
    		String b2=b1.getText();
    		String c2=c1.getText();
    		String a3=password;
    		ResultSet rs=null;
    		Connection conn=null;
    		PreparedStatement checkUser=null;
    		String sql="UPDATE jiben SET mima=? WHERE mima=? and xuehao=?";
    		if(!(a2.equals(a3)))
    		{
    		JOptionPane.showMessageDialog(null, "原密码输入错误\n请确认后重新输入!","提示",JOptionPane.INFORMATION_MESSAGE);
    		a1.setText("");
    		b1.setText("");
    		c1.setText("");
    		}
    		else if(!(b2.equals(c2)))
    		{
    			JOptionPane.showMessageDialog(null, "新旧密码输入不一致\n请确认后重新输入!","提示",JOptionPane.INFORMATION_MESSAGE);
    		b1.setText("");
    		c1.setText("");
    		}
    	    else
    		{
    			try
    			{
    			 conn = DBConnection.getConncetion();	
    		     checkUser = conn.prepareStatement(sql);
    		     checkUser.setString(1, b2);
    		     checkUser.setString(2,a3);
    		     checkUser.setString(3, xuehao);
    		     int i=checkUser.executeUpdate();
       	     	 if(i!=0)
    			{
    				JOptionPane.showMessageDialog(null, "密码设置成功!","提示",JOptionPane.INFORMATION_MESSAGE);
    				}
    			}
    			catch(Exception m)
    			{
    				m.printStackTrace();
    			   }
    			finally
    			{
    			try
    			{
    				conn.close();
    			    checkUser.close();
    			}
    			catch(SQLException h)
    			{
    				h.printStackTrace();
    			}
    			}
 }
               }
    	}
		);
    e.addActionListener(new ActionListener()
    {
    	public void actionPerformed(ActionEvent e)
    	{
    		a1.setText("");
    		b1.setText("");
    		c1.setText("");
    	}
    });
	}
}
class B implements ActionListener
{
	public void actionPerformed(ActionEvent e)
	{   studentlogin here=new studentlogin();
	    UsersDAO userDao = new UsersDAO();
	    String[][] jieguo1=new String[10][2];
	    JPanel i=new JPanel();
		JPanel j=new JPanel();
		JButton p=new JButton("修改密码");
        Color z=new Color(0,255,0); 
        Font w1=new Font("SansSerif",Font.BOLD,20);
        String[] jieguo=new String[4];
	    usersName=text1.getText();
		password=text2.getText();
        xuehao=text4.getText();		
        p.setFont(w1);
	    if (userDao.checkUser(usersName, password,xuehao)) {
			studentin a=new studentin();
			a.setSize(900,600);
			a.setVisible(true);
			a.setTitle("登录成功");
			a.setExtendedState(MAXIMIZED_BOTH);
			jieguo=here.chaxun(usersName,xuehao);
			(a.b1).setText(jieguo[0]);
			(a.d1).setText(jieguo[1]);
			(a.c1).setText(jieguo[2]);
			(a.e1).setText(jieguo[3]);
		     jieguo1=here.chaxun1(text4.getText());
			for(int n=0;n<here.i;n++)
			{
				JPanel s=new JPanel();
				s.setBackground(z);
				s.setLayout(new FlowLayout(FlowLayout.CENTER,15,10));
				Font w=new Font("SansSerif",Font.BOLD,20);
				String d1=jieguo1[n][0]+":";
			    JLabel h1=new JLabel(d1,SwingConstants.LEFT);
			    h1.setFont(w);
          	    s.add(h1);
                String d2=jieguo1[n][1];
			    JLabel h2=new JLabel(d2,SwingConstants.RIGHT);
			    h2.setFont(w);
			    s.add(h2);
			    h2.setBackground(z);
			    a.add(s);
			}
		     p.addActionListener(new ActionListener()
					{
				public void actionPerformed(ActionEvent e)
				{
	             change a=new change();
	             a.setSize(300,200);
	             a.setVisible(true);
	             a.setLocation(300, 250);
	             a.setTitle("修改密码");
				}
});
			i.setLayout(new FlowLayout());
			i.add(p);
			a.add(j);
			a.add(i);
			text1.setText("");
			text2.setText("");
	        text4.setText("");
		}
			else {
		JOptionPane.showMessageDialog(null, "用户名,学号或密码错误","登录失败",JOptionPane.ERROR_MESSAGE);
		text1.setText("");
		text2.setText("");
		text4.setText("");
	}
}
}
}



⌨️ 快捷键说明

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