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

📄 学生管理系统.java

📁 管理学生信息
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.sql.*;
class  学生管理系统 extends JDialog implements ActionListener
{
	JPanel p1=new JPanel();
	JPanel p2=new JPanel();
	JPanel p3=new JPanel();
	JPanel p4=new JPanel();
	JPanel p5=new JPanel();
	JTextField txtUserName=new JTextField(15);
	JPasswordField txtPassword=new JPasswordField(15);
	JButton ok=new JButton("确定");
	JButton cancel=new JButton("取消");
	public 学生管理系统(){
		setModal(true);
		setBackground(Color.LIGHT_GRAY);
		Container contentPane=this.getContentPane();
		contentPane.setLayout(new GridLayout(5,1));
		p2.add(new JLabel("用户名:"));p2.add(txtUserName);
		p3.add(new JLabel("  密码:"));p3.add(txtPassword);
		p4.add(ok);p4.add(cancel);
		ok.addActionListener(this);
		cancel.addActionListener(this);
		txtUserName.addActionListener(this);
		txtPassword.addActionListener(this);
		contentPane.add(p1);
		contentPane.add(p2);
		contentPane.add(p3);
		contentPane.add(p4);
		contentPane.add(p5);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setSize(500,375);
		Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
		Dimension my=this.getSize();
		setLocation((screen.width-my.width)/2,(screen.height-my.height)/2);
	    setTitle("登录窗口");
		setResizable(false);
		setVisible(true);

	}
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==ok||e.getSource()==txtPassword){
		String name=txtUserName.getText().trim();
		String pass=String.valueOf(txtPassword.getPassword());
		Connection con=null;
		Statement sm=null;
		String command=null;
		try{
			//DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			con=DriverManager.getConnection("jdbc:odbc:student");
		}catch(Exception ex){
		System.out.println(ex.getMessage());
		}
		try{
			sm=con.createStatement();
			command="select username,arth from yonghu where username='"+name+"' and pws='"+pass+"'";
			ResultSet re=sm.executeQuery(command);
			if(re.next())
			{
				int x=Integer.parseInt(re.getString("arth"));
				if(x==2)
					new MainWindow3(name);
				else
					if(x==1)
						new MainWindow1(name);
					else
						new MainWindow2(name);
				dispose();
			}
			else{
				JOptionPane.showMessageDialog(null,"用户名或密码错误!");
				txtUserName.requestFocus();
				txtUserName.setSelectionStart(0);
				txtUserName.setSelectionEnd(txtUserName.getText().length());
			}
		}catch(Exception em){
			System.out.println(em.getMessage());
			}
		}
		else if(e.getSource()==cancel){
			dispose();
			System.exit(0);
		}
		else if(e.getSource()==txtUserName)
			txtPassword.requestFocus();
	}
	public static void main(String[] args){
		JDialog.setDefaultLookAndFeelDecorated(true);
		Font font=new Font("JFrame",Font.PLAIN,14);
		Enumeration keys=UIManager.getLookAndFeelDefaults().keys();
		while(keys.hasMoreElements()){
			Object key=keys.nextElement();
			if(UIManager.get(key) instanceof Font)
				UIManager.put(key,font);
		}
		new 学生管理系统();
	}
}

⌨️ 快捷键说明

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