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

📄 j04326e5studentsmanager.java

📁 java程序 学生信息管理系统 数据库采用acce
💻 JAVA
字号:
package com.studentFrame;

/*学生信息管理系统
功能:学生个人信息管理;学生课程信息管理*
开发者:计算机043 徐健
开发日期:2006-10-26
版本:5.0 */
           
import java.awt.*;
import java.awt.event.*;
import javax.swing.JPasswordField;
import javax.swing.border.*;
import javax.swing.JPanel;
import javax.swing.*;
import java.sql.*;

public class j04326e5StudentsManager
{
	public static void main(String args[])
	{
		new ManagerFrame();
	}
}
/*程序主窗口*/
 class ManagerFrame extends JFrame implements ActionListener,ItemListener    
{
	JPanel p1,p2,p3;
	JButton btstulog,btcourse,btlog,btclose;
	Font font;
	JPasswordField pas;
	TextField tfusername;
	Label lab1,lab2,lab3,prompt;
	Dialog logdialog;
    int temp;    //若是个人信息查询值为1,课程查询值为2
    Choice userkind;    //用户类型
    static String user = "学生";   //默认用户类型为学生
    StudentInfo si;      
	ManagerFrame()                 
	{
		Container c = getContentPane();
		c.setLayout(new GridLayout(3,1));
		prompt = new Label("    欢迎使用学生信息管理系统");
		font = new Font("TimesRoman",Font.BOLD,30);
		prompt.setFont(font);
		
		p1 = new JPanel();
		p1.setBorder(new TitledBorder("信息管理"));
		btstulog = new JButton("学生个人信息校对");
		p1.add(btstulog);
		
		p2 = new JPanel();
		p2.setBorder(new TitledBorder("课程管理"));
		btcourse = new JButton("课程信息查询");
		p2.add(btcourse);	
		/*登陆对话框*/
		logdialog = new Dialog(this,"登录",true);       
		p3 = new JPanel();
		lab1 = new Label("用  户  名");
		lab2 = new Label("密  码");
		lab3 = new Label("登 陆 类 型");
		btlog = new JButton("登 录");
		btclose = new JButton("关 闭");
		pas = new JPasswordField(10);
		tfusername = new TextField(10);
		userkind = new Choice();
		userkind.add("学生");
		userkind.add("教师");
		userkind.add("管理员");
		p3.setLayout(new GridLayout(4,2));
		p3.add(lab1);
		p3.add(tfusername);
		p3.add(lab2);
		p3.add(pas);
	    p3.add(lab3);
	    p3.add(userkind);
	    p3.add(btlog);
	    p3.add(btclose);
		logdialog.add("Center",p3);
		
		c.add(prompt);
		c.add(p1);
		c.add(p2);
		/*监听事件*/
		btstulog.addActionListener(this);
		btcourse.addActionListener(this);
		btlog.addActionListener(this);
		btclose.addActionListener(this);
		userkind.addItemListener(this);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(460,300);
		setLocation(200,200);
		setVisible(true);
	}
	public void actionPerformed(ActionEvent e)
	{
	   String title[] ={ "学生基本信息表","课程表"};
	   if(e.getSource()==btstulog)   
	   {
	   	   /*显示登陆对话框*/
		   temp = 1;
		   logdialog.setSize(300,200);
		   logdialog.setLocation(200,160);
		   logdialog.show();
	   }
	   else if(e.getSource() == btcourse)
	   {
	      /*显示登陆对话框*/
	       temp = 2;
		   logdialog.setSize(300,200);
		   logdialog.setLocation(200,160);
		   logdialog.show();
	   }
		else if(e.getSource() == btlog)   //登录
		{
			String username,password;
			username = tfusername.getText().toString();
		    password = String.valueOf(pas.getPassword());
		    tfusername.setText("");
		    pas.setText("");
		    logdialog.dispose();
		    if(valid(username,password))
		    {
		      if(temp == 1)
		      {
		         if(user.equals("学生"))
		           new StudentFrame(si);
		         else if(user.equals("教师"))
		         /*false 表示教师不可以修改表格中的内容*/
		           new TableFrame(false,title[0]); 
		         else  new TableFrame(true,title[0]);
			   }
			  else if(temp == 2)
			  {
			  	if(user.equals("学生"))
		            new CourseFrame(username);
		         else if(user.equals("教师"))
		          /*false表示教师不可以修改表格中的内容*/
		           new TableFrame(false,title[1]);
		         else  new TableFrame(true,title[1]);
			  } 
			 }
		    else
		    {
		     JOptionPane.showMessageDialog(this, "密码或用户名错误", "alert", JOptionPane.ERROR_MESSAGE);
		     tfusername.setText(username);
		     logdialog.show();
	        }
	    }
	  else if(e.getSource()==btclose)
	       logdialog.dispose();
	}
	public void itemStateChanged(ItemEvent e1)
	{
		Choice temp;
		if(e1.getItemSelectable() instanceof Choice)
		 {
			temp = (Choice)(e1.getItemSelectable());
			user = temp.getSelectedItem();	
		 }
	} 
	boolean valid(String ID,String pas)          //判断用户名与密码是否正确
	{
		String url="jdbc:odbc:javadbc";
        String username="";
        String password="";
        Connection con =null;
        Statement stmt = null;
        ResultSet rs = null;
        String sql;
        if(user.equals("学生"))
         /*学生表*/
          sql = "select * from student where id = '"+ID+"' and password = '"+pas+"'";    
        else if(user.equals("教师"))
        /*教师表*/
          sql = "select * from teacher where username = '"+ID+"' and password = '"+pas+"'";   
        else 
        /*管理员表*/
          sql = "select * from admin where username = '"+ID+"' and password = '"+pas+"'"; 
	  try{
	  	  	/*连接数据库*/
	      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          con=DriverManager.getConnection(url,username,password);
          stmt=con.createStatement();
          rs=stmt.executeQuery(sql);
          while(rs.next())
          {
           if(user.equals("学生"))
              si = new StudentInfo(rs.getString(1),rs.getString(2),rs.getString(3),
                                   rs.getString(4),rs.getString(5),rs.getString(6),
                                   rs.getString(7),rs.getString(8),rs.getString(9));
          return true;
          }
         }
       catch(SQLException ex)
       {
       	System.out.println(ex.getMessage());
       }
       catch(Exception e)  {}
        /*关闭数据库连接*/
       finally{
        	   try{
        	        if(rs!=null)
        	           rs.close();
        	        if(stmt!=null)
                       stmt.close();
                    con.close();
                  }
              catch(SQLException ex)
                  {
         	         ex.printStackTrace();
                  }  
              }        
		 return false;
	}
}


 
 



⌨️ 快捷键说明

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