java教务系统实现学生选修课程,老师为选择该课程的学生打分数,学生查看成绩,学生注册,老师注册

1、Department

package com.cqcet.dao;

public class Department {

	public Department(String string) {
		// TODO Auto-generated constructor stub
	}
	

}

2、Login

package com.cqcet.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import om.cqcet.com.DBUtile;

public class Login {
	private String username;
	private String password;
	
	public Login(String username,String password){
		this.username=username;
		this.password = password;
	}				
	public String login(){
	String ret=null;
	String sql="SELECT id FROM student WHERE username='"+username+"'and password = '"+password+"'";
	DBUtile dbu=new DBUtile();
	ResultSet rs=dbu.query(sql);
	try{
		while(rs.next())
			ret=rs.getString(1);					
			
		}catch(SQLException e){
		e.printStackTrace();
		}
	return ret;
}
	
}

3、QueryDepartment

package com.cqcet.dao;

import java.sql.ResultSet;



import om.cqcet.com.DBUtile;

public class QueryDepartment {

	public ResultSet queryDepartment() {
		// TODO Auto-generated method stub
		ResultSet rs=null;
		DBUtile dbu=new DBUtile();
		String sql="select * from department";
		rs=dbu.query(sql);
		
		return rs;
	}

}

4、QueryDiagnose

package com.cqcet.dao;

import java.sql.ResultSet;



import om.cqcet.com.DBUtile;

public class QueryDiagnose {

	public ResultSet queryDepartment() {
		// TODO Auto-generated method stub
		ResultSet rs=null;
		DBUtile dbu=new DBUtile();
		String sql="select * from department";
		rs=dbu.query(sql);
		
		return rs;
	}

}

5、QueryDoctor

package com.cqcet.dao;

import java.awt.Container;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import his.Login_2;
import om.cqcet.com.DBUtile;

public class QueryDoctor  extends JFrame{
	JTable table =null;
	DefaultTableModel  tableModel;
	ResultSet rs=null;
	String p_id=null;
	public QueryDoctor(ResultSet rs, String p_id){
		this.rs=rs;
		this.p_id=p_id;
		setTitle("学生端——选课界面");
		ImageIcon img = new ImageIcon("src/picture/a3.jpg");
		JLabel imgLabel = new JLabel(img);
		this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
		imgLabel.setBounds(0,0,800,500 );
		Container contain = this.getContentPane();
		((JPanel) contain).setOpaque(false); 
		setLayout(null);
		setBounds(600,300,800,600);
		//setBounds(100,100,800,600);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		table=new JTable();
		tableModel=new DefaultTableModel();
		table.setModel(tableModel);
		JScrollPane scrollPane=new JScrollPane(table);
		scrollPane.setBounds(0, 0, 700, 450);
		this.add(scrollPane);
		this.setVisible(true);
		try{
			queryData();
		}catch(Exception e){
			
		}
		table.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub
				int index=table.getSelectedRow();
				String id=(String)table.getValueAt(index, 0);
				String sql="insert into regestraion(student_id,teacher_id,xuanke_Date)values('"+p_id+"','"+id+"',now())";
				DBUtile dbu=new DBUtile();
				if(dbu.update(sql)>=1){
					System.out.println("选课成功");
					Login_2 regFrame = new Login_2();
				}
			}
		});
	}
	private void queryData() throws Exception{
		int count=0;
		ResultSetMetaData rsmd=null;
		rsmd=rs.getMetaData();
		count=rsmd.getColumnCount();
		for(int i=1;i<=count;i++){
			tableModel.addColumn(rsmd.getColumnName(i));
		}
		String[] row=new String[count];
		while(rs.next()){
			for(int i=0;i<count;i++){
				row[i]=rs.getString(i+1);
				
			}
			tableModel.addRow(row);
			
	}
	}
}

6、xuanke1

package com.cqcet.dao;

import java.sql.ResultSet;



import om.cqcet.com.DBUtile;



import java.sql.ResultSet;

import om.cqcet.com.DBUtile;

public class xuanke1 {

	public ResultSet querydoctor(String p_id) {
		// TODO Auto-generated method stub
		ResultSet rs=null;
		
		DBUtile dbu=new DBUtile();
		String sql="select * from chengji  where student_id='"+p_id +"'";
		rs=dbu.query(sql);
		
		return rs;
	}

}

7、LoginJfram

package com.cqcet.fram;
import java.awt.*;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.*;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.cqcet.dao.Login;
public class LoginJfram  extends JFrame{
	public LoginJfram (){
		setTitle("学生成绩管理系统---学生端");
		ImageIcon img = new ImageIcon("src/picture/a1.jpg");
		JLabel imgLabel = new JLabel(img);
		this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
		imgLabel.setBounds(0,0,800,500 );
		Container contain = this.getContentPane();
		((JPanel) contain).setOpaque(false); 
		setLayout(null);
		setBounds(600,300,800,600);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		Container c=getContentPane();
		JLabel l=new JLabel();
		JTextField jt=new JTextField();
		jt.setText("");
		JPasswordField jp=new JPasswordField();
		JButton b=new JButton("登录");
		JButton b1=new JButton("取消");
		JButton b2=new JButton("注册");
		jt.setBounds(80, 80, 200, 30);
		c.add(jt);
		jp.setBounds(80, 120, 200,30);
		c.add(jp);
		JLabel l1=new JLabel("Name:");
		JLabel l2=new JLabel("Password:");
		l1.setBounds(15, 75, 50, 50);
		l2.setBounds(15, 105, 80, 50);
		c.add(l1);
		c.add(l2);
		b.setBounds(90, 170, 80, 50);
		b.setFont(new Font("",Font.PLAIN,15));
		b1.setBounds(210, 170, 80, 50);
		b1.setFont(new Font("",Font.PLAIN,15));
		b2.setBounds(0,170,80,50);
		b2.setFont(new Font("",Font.PLAIN,15));
		c.add(b1);
		c.add(b);
		c.add(b2);
		c.setBackground(Color.WHITE);
		setResizable(false);
		setVisible(true);
		
		b.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent actionEvent) {
				// TODO Auto-generated method stub
			System.out.println("Value:"+"\t\t"+jt.getText());
			char a[]=jp.getPassword();
			String b=new String(a);
			String b1=new String(jt.getText());
			System.out.println("password"+"\t"+b);
			System.err.println("----end----");
			
			
			Login lg=new Login(b1,b);
			String p_id=lg.login();
			if((Integer.parseInt(p_id)>=1)){
				System.out.println("登录成功");
				setVisible(false);
				new P_Main(b1,p_id);//跳转
			}else{
				System.out.println("登录失败");
			}
			}
		});
		b1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent actionEvent) {
				// TODO Auto-generated method stub
				System.exit(0);
			}
		});
		b2.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent  actionEvent) {
				// TODO Auto-generated method stub
				new Regis();
			}
		});
	}

}

8、P_Main

package com.cqcet.fram;


import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.cqcet.dao.QueryDepartment;
import com.cqcet.dao.xuanke1;

		public class P_Main extends JFrame {
			String p_id=null;
			public P_Main(String username,String p_id){
				this.p_id=p_id;
				setTitle("学生端主界面");
				ImageIcon img = new ImageIcon("src/picture/a3.jpg");
				JLabel imgLabel = new JLabel(img);
				this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
				imgLabel.setBounds(0,0,800,500 );
				setLayout(null);
				setBounds(600,300,800,600);
				setDefaultCloseOperation(EXIT_ON_CLOSE);
				
		JPanel jp1=new JPanel();
		jp1.setLayout(null);
		jp1.setBounds(20, 20, 760, 560);
		
		JLabel jl1=new JLabel("欢迎"+username+"同学登录学生成绩管理系统");
		jl1.setBounds(150, 80, 500, 200);
		jl1.setFont(new Font("",Font.PLAIN,30));
		
		jp1.add(jl1);
		
		JButton jb1=new JButton("请您选择课程");
		jb1.setFont(new Font("",Font.PLAIN,20));
		jb1.setBounds(200, 250, 160, 60);
		jp1.add(jb1);	
		add(jp1);
		setVisible(true);
		
		JButton jb2=new JButton("请您查看成绩");
		jb2.setFont(new Font("",Font.PLAIN,20));
		jb2.setBounds(400, 250, 160, 60);
		jp1.add(jb2);	
		add(jp1);
		setVisible(true);
		
		
		jb1.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				QueryDepartment qd=new QueryDepartment();
				ResultSet rs=qd.queryDepartment();
				QueryDeparMentsFram qdm=new QueryDeparMentsFram(rs,p_id);
				
			}
			
		});
		jb2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent  actionEvent) {
				ResultSet rs = null;
				// TODO Auto-generated method stub
				xuanke1 qd=new xuanke1();
				ResultSet rs1=qd.querydoctor(p_id);
				new Xuanke(rs1, p_id);
			}
		});
	}

}

9、QueryDeparMentsFram

package com.cqcet.fram;

import java.awt.Container;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.ResultSet;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import com.cqcet.dao.QueryDepartment;
import com.cqcet.dao.QueryDoctor;

import om.cqcet.com.DBUtile;

import java.sql.ResultSetMetaData;

public class QueryDeparMentsFram extends JFrame{
	JTable table=null;
	DefaultTableModel tableModel;
			
	private Object[][]data=null;
	ResultSet rs=null;
	Vector<Vector<Object>> dataVector=null;
	String p_id=null;		
	public QueryDeparMentsFram(ResultSet rs,String p_id){
		this.rs=rs;		
		setTitle("学生端选择所属院系");
		ImageIcon img = new ImageIcon("src/picture/a3.jpg");
		JLabel imgLabel = new JLabel(img);
		this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
		imgLabel.setBounds(0,0,800,500 );
		Container contain = this.getContentPane();
		((JPanel) contain).setOpaque(false); 
		setLayout(null);
		setBounds(600,300,800,600);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		table=new JTable();
		tableModel=new DefaultTableModel();
		
		table.setModel(tableModel);
		JScrollPane scrollPane=new JScrollPane(table);
		scrollPane.setBounds(0, 0, 700, 450);
		this.add(scrollPane);
		this.setVisible(true);
		try{
			queryData();
		}catch(Exception e){
			
		}
	
	table.addMouseListener(new MouseAdapter(){
		public void mouseClicked(MouseEvent e){
			int index=table.getSelectedRow();
			String id=(String)table.getValueAt(index, 0);
			String sql="select * from teacher where depart_id="+id;
			DBUtile dbu=new DBUtile();
			ResultSet rs=dbu.query(sql);
			new QueryDoctor(rs,p_id);
		}
	});
	}

	private void queryData()  throws Exception{
		// TODO Auto-generated method stub
		  System.out.println("just test!");
	        int count=0;
	        ResultSetMetaData rsmd=null;
	        
	        rsmd=rs.getMetaData();
	        count=rsmd.getColumnCount();
	        
	        for(int i=1; i<=count;i++){
	            tableModel.addColumn(rsmd.getColumnName(i));
	        }
	        String[] row=new String[count];
	        while(rs.next()){
	            for(int i =0;i<count;i++){
	                row[i]=rs.getString(i+1);
	            }
	            tableModel.addRow(row);
	        }
	    }
}

	
	

10、ReginsDoctor

package com.cqcet.fram;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;

import om.cqcet.com.DBUtile;

public class ReginsDoctor extends JFrame {
	public ReginsDoctor() {
		setTitle("教师注册页面");
		ImageIcon img = new ImageIcon("src/picture/a1.jpg");
		JLabel imgLabel = new JLabel(img);
		this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
		imgLabel.setBounds(0,0,800,500 );
		Container contain = this.getContentPane();
		((JPanel) contain).setOpaque(false); 
		setLayout(null);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setBounds(600,300,800,600);
		
		Container c=getContentPane();
		
		JLabel jl0=new JLabel();
		JTextField jt=new JTextField();
		JTextField jt1=new JTextField();
		JTextField jt2=new JTextField();
		JPasswordField jp=new JPasswordField();
		JPasswordField jp1=new JPasswordField();
		
		JButton b0=new JButton("注册");

		
		jt.setBounds(80,90,200,23);//xingming
		c.add(jt);
		jp.setBounds(80,120,200,23);//mima
		c.add(jp);
		jp1.setBounds(80,150,200,23);
		c.add(jp1);
		jt1.setBounds(80,180,200,23);//depart——id
		c.add(jt1);
		jt2.setBounds(80,210,200,23);//course
		c.add(jt2);
		

		
		JLabel jl4=new JLabel("depart_id:");
		JLabel jl5=new JLabel("course:");
		JLabel jl1=new JLabel("Name:");
		JLabel jl2=new JLabel("password:");
		JLabel jl3=new JLabel("confirmapassword:");
		
		jl1.setBounds(15,75,50,50);
		jl2.setBounds(15,105,80,50);
		jl3.setBounds(15,135,80,50);
		jl4.setBounds(15,165,80,50);
		jl5.setBounds(15,195,80,50);
		
		c.add(jl1);
		c.add(jl2);
		c.add(jl3);
		c.add(jl4);
		c.add(jl5);
		
		b0.setBounds(100,240,100,50);
		b0.setFont(new Font("",Font.PLAIN,15));
		
		c.add(b0);
		
		c.setBackground(Color.WHITE);
		setResizable(false);
		setVisible(true);
		b0.addActionListener(new ActionListener() {  
		    @Override  
		    public void actionPerformed(ActionEvent e) {  
		        String username = jt.getText();  
		        String password = new String(jp.getPassword());  
		        String confirmPassword = new String(jp1.getPassword());  
		        String depart_id = jt1.getText();  
		        String course= jt2.getText(); 
		        
		  
		        // 验证密码是否匹配  
		        if (!password.equals(confirmPassword)) {  
		            JOptionPane.showMessageDialog(ReginsDoctor.this, "密码不匹配!", "错误", JOptionPane.ERROR_MESSAGE);  
		            return;  
		        }  
		        try (Connection conn = DBUtile.getConnection(); // 有一个静态方法getConnection()  
		             PreparedStatement pstmt = (PreparedStatement) conn.prepareStatement("INSERT INTO teacher "
		             		+ "(username, password,depart_id,course) VALUES (?, ?,?, ?)")) {  
		  
		            pstmt.setString(1, username);  
		            pstmt.setString(2, password); 
		            pstmt.setString(3, depart_id); 
		        
					pstmt.setString(4, course); 
		            
		  
		            int rowsAffected = pstmt.executeUpdate();  
		            if (rowsAffected > 0) {  
		                JOptionPane.showMessageDialog(ReginsDoctor.this, "注册成功!", "成功", JOptionPane.INFORMATION_MESSAGE);  
		                dispose();
		            } else {  
		                JOptionPane.showMessageDialog(ReginsDoctor.this, "注册失败!", "错误", JOptionPane.ERROR_MESSAGE);  
		            }  
		        } catch (SQLException ex) {  
		            ex.printStackTrace(); 
		            JOptionPane.showMessageDialog(ReginsDoctor.this, "数据库错误:" + ex.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);  
		        }  
		    }  
		});  }}

11、Regis

package com.cqcet.fram;
	import java.awt.Color;
	import java.awt.Container;
	import java.awt.Font;
	import java.awt.event.ActionEvent;
	import java.awt.event.ActionListener;
	import java.sql.SQLException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
	import javax.swing.JFrame;
	import javax.swing.JLabel;
	import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
	import javax.swing.JTextField;

	import om.cqcet.com.DBUtile;
	import com.mysql.jdbc.Connection;
	import com.mysql.jdbc.PreparedStatement;

	
	public class Regis extends JFrame{
		public Regis() {
			setTitle("学生注册页面");
			ImageIcon img = new ImageIcon("src/picture/a1.jpg");
			JLabel imgLabel = new JLabel(img);
			this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
			imgLabel.setBounds(0,0,800,500 );
			Container contain = this.getContentPane();
			((JPanel) contain).setOpaque(false); 
			setLayout(null);
			setDefaultCloseOperation(EXIT_ON_CLOSE);
			setBounds(600,300,800,600);
			
			Container c=getContentPane();
			JLabel jl0=new JLabel();
			JTextField jt=new JTextField();
			
			JPasswordField jp=new JPasswordField();
			JPasswordField jp1=new JPasswordField();
			JButton b0=new JButton("注册");
			
			jt.setBounds(80,90,200,23);
			c.add(jt);
			jp.setBounds(80,120,200,23);
			c.add(jp);
			jp1.setBounds(80,150,200,23);
			c.add(jp1);
			JLabel jl1=new JLabel("Name:");
			JLabel jl2=new JLabel("password:");
			JLabel jl3=new JLabel("confirmapassword:");
			jl1.setBounds(15,75,50,50);
			jl2.setBounds(15,105,80,50);
			jl3.setBounds(15,135,80,50);
			c.add(jl1);
			c.add(jl2);
			c.add(jl3);
			b0.setBounds(90,200,100,60);
			b0.setFont(new Font("",Font.PLAIN,15));
			
			c.add(b0);
			
			c.setBackground(Color.WHITE);
			setResizable(false);
			setVisible(true);
			b0.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					// TODO Auto-generated method stub
					 String username = jt.getText();
		             String password = new String(jp.getPassword());
		             String confirmPassword = new String(jp1.getPassword());

		                // 验证密码是否一致
		                if (password.equals(confirmPassword)) {
		                    // 创建数据库连接
		                    Connection conn = (Connection) DBUtile.getConnection();
		                    if (conn != null) {
		                        try {
		                            // 准备SQL语句
		                            String sql = "INSERT INTO student (username, password) VALUES (?, ?)";
		                            PreparedStatement pstmt = (PreparedStatement) conn.prepareStatement(sql);
		                            pstmt.setString(1, username);
		                            pstmt.setString(2, password);

		                            // 执行SQL语句
		                            int rowsAffected = pstmt.executeUpdate();
		                            if (rowsAffected > 0) {
		                                System.out.println("注册成功,用户名: " + username + ", 密码: " + password);
		                                // 关闭注册窗口
		                                dispose();
		                            } else {
		                                JOptionPane.showMessageDialog(null, "注册失败,请重试!");
		                            }

		                            // 关闭数据库连接
		                            conn.close(); // 使用标准JDBC的close方法关闭连接
		                        } catch (SQLException se) {
		                            se.printStackTrace();
		                        }
		                    }
		                } else {
		                    JOptionPane.showMessageDialog(null, "两次输入的密码不一致,请重新输入!");
		                }

				}
			});
			}
}

12、Xuanke

package com.cqcet.fram;


import java.awt.Container;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import com.cqcet.dao.QueryDoctor;
import com.cqcet.zhen.Doctorzhen;
import om.cqcet.com.DBUtile;


public class Xuanke extends JFrame{
		JTable table=null;
		DefaultTableModel tableModel;
				
		private Object[][]data=null;
		ResultSet rs=null;
		Vector<Vector<Object>> dataVector=null;
		String d_id=null;		
		public Xuanke(ResultSet rs,String d_id){
			this.rs=rs;		
			setTitle("学生查看成绩");
			ImageIcon img = new ImageIcon("src/picture/a3.jpg");
			JLabel imgLabel = new JLabel(img);
			this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
			imgLabel.setBounds(0,0,800,500 );
			Container contain = this.getContentPane();
			((JPanel) contain).setOpaque(false); 
			setLayout(null);
			//setBounds(100,100,800,600);
			setBounds(600,300,800,600);
			setDefaultCloseOperation(EXIT_ON_CLOSE);
			table=new JTable();
			tableModel=new DefaultTableModel();
			
			table.setModel(tableModel);
			JScrollPane scrollPane=new JScrollPane(table);
			scrollPane.setBounds(0, 0, 700, 450);
			this.add(scrollPane);
			this.setVisible(true);
			try{
				queryData();
			}catch(Exception e){
			}
		table.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent e){
				int index=table.getSelectedRow();
				String id=(String)table.getValueAt(index, 0);
				String sql="select * from chengji where student_id="+id;
				DBUtile dbu=new DBUtile();
				ResultSet rs=dbu.query(sql);
				new Doctorzhen();
				}  }  );  }

		
		
		
		private void queryData()  throws Exception{
			// TODO Auto-generated method stub
			  System.out.println("just test!");
		        int count=0;
		        ResultSetMetaData rsmd=null;
		        
		        rsmd=rs.getMetaData();
		        count=rsmd.getColumnCount();
		        
		        for(int i=1; i<=count;i++){
		            tableModel.addColumn(rsmd.getColumnName(i));
		        }
		        String[] row=new String[count];
		        while(rs.next()){
		            for(int i =0;i<count;i++){
		                row[i]=rs.getString(i+1);
		            }
		            tableModel.addRow(row);}}}

13、Doctorzhen

package com.cqcet.zhen;

import javax.swing.*;

import his.Login_2;
import his.QueryDoctorFr;
import om.cqcet.com.DBUtile;
import java.awt.*;  
import java.awt.event.ActionEvent;  
import java.awt.event.ActionListener;  
import java.sql.Connection;  
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;    
public class Doctorzhen extends JFrame {  
    private JTextField patientIdField;  
    private JTextField doctorIdField;  
    private JTextField diaTextField;  
    private JTextField diaTextField1; 
    public Doctorzhen() {  
		Container contain = this.getContentPane();
		((JPanel) contain).setOpaque(false); 

        setTitle("教师打分数页面");  
        ImageIcon img = new ImageIcon("src/picture/a3.jpg");
		JLabel imgLabel = new JLabel(img);
		this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
		imgLabel.setBounds(0,0,800,500 );
        setLayout(null);
		setBounds(600,300,800,600);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
  
		JLabel patientIdLabel1 = new JLabel("学生:");
		patientIdLabel1.setBounds(50, 50, 60, 25); 
		add(patientIdLabel1);
        patientIdField = new JTextField(10); 
        patientIdField.setBounds(120, 50, 200, 25);  
        add(patientIdField);  
  
        JLabel doctorIdLabel = new JLabel("教师:");  
        doctorIdLabel.setBounds(50, 80, 60, 25);  
        add(doctorIdLabel);  
        doctorIdField = new JTextField(10);   
        doctorIdField.setBounds(120, 80, 200, 25);  
        add(doctorIdField);  
        
  
        JLabel diaTextLabel = new JLabel("分数:");  
        diaTextLabel.setBounds(50, 110, 60, 25);  
        add(diaTextLabel);  
        diaTextField = new JTextField(10); 
        diaTextField.setBounds(120, 110, 200, 30);   
        add(diaTextField);  
        
        JLabel diaTextLabel1 = new JLabel("课程:");  
        diaTextLabel1.setBounds(50, 150, 60, 25);  
        add(diaTextLabel1);  
        diaTextField1 = new JTextField(10); 
        diaTextField1.setBounds(120, 150, 200, 30);   
        add(diaTextField1);  
       
        JButton saveButton = new JButton("保存");  
        saveButton.setBounds(150, 200, 100, 30);  
        saveButton.addActionListener(new ActionListener() {  
            @Override  
            public void actionPerformed(ActionEvent e) {  
                String patient_id = patientIdField.getText();  
                String doctor_id = new String(doctorIdField.getText());  
                String dia_text = diaTextField.getText();
                String kecheng=diaTextField1.getText();
  
                saveDiagnose(patient_id, doctor_id , dia_text,kecheng); 
            }  
        });  
        add(saveButton);  
  
        setVisible(true);  
    }  
  
    private void saveDiagnose(String patient_id, String doctor_id, String dia_text,String kecheng) {  
        Connection conn = null;  
        PreparedStatement pstmt = null;  
        PreparedStatement deleteStmt = null; 
        try {  
          
            conn = DBUtile.getConnection(); 
  
            String sql = "INSERT INTO chengji (student_id, teacher_id, chengji,kecheng) VALUES (?,?, ?, ?)";  
  
            pstmt = conn.prepareStatement(sql);  
            pstmt.setString(1, patient_id);  
            pstmt.setString(2, doctor_id);  
            pstmt.setString(3, dia_text); 
            pstmt.setString(4, kecheng);
  
            pstmt.executeUpdate();  
  
            JOptionPane.showMessageDialog(null, "分数结果保存成功!");  
            

        } catch (SQLException ex) {  
          
            ex.printStackTrace();  
            JOptionPane.showMessageDialog(null, "保存信息时出错:" + ex.getMessage());  
        } finally {  
           
            try {  
            	if (deleteStmt != null) deleteStmt.close(); 
               if (pstmt != null) pstmt.close();  
                if (conn != null) conn.close();  
               
                QueryDoctorzhen nextFrame = new QueryDoctorzhen(); 
                nextFrame.setVisible(true); 
               this.setVisible(false); 
               this.dispose();
               
            } catch (SQLException ex) {  
                ex.printStackTrace();  
            }  
        }  
    }  
  
    public static void main(String[] args) {  
        new Doctorzhen();  
    }

	public void showDiagnose(ResultSet rsDiagnose) {
		// TODO Auto-generated method stub
		
	}  
}

14、QueryDoctorzhen

package com.cqcet.zhen;    
import java.awt.*;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;

import javax.*;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.cqcet.dao.Login;

import his.DoctorRegisterFr;
import his.Login_2;
import his.QueryDoctor;
import his.QueryDoctorFr;

public class QueryDoctorzhen  extends JFrame{
	public QueryDoctorzhen (){
		setTitle("学生成绩管理系统---请选择你的下一步");
		ImageIcon img = new ImageIcon("src/picture/a3.jpg");
		JLabel imgLabel = new JLabel(img);
		this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
		imgLabel.setBounds(0,0,800,500 );
		Container contain = this.getContentPane();
		((JPanel) contain).setOpaque(false); 
		setLayout(null);
		setBounds(600,300,800,600);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		Container c=getContentPane();
		JLabel l=new JLabel();
		JTextField jt=new JTextField();
		jt.setText("");
		JPasswordField jp=new JPasswordField();
	//	JButton b=new JButton("返回待诊断病人界面");
//		JButton b1=new JButton("就诊结束返回医生界面");
		JButton b2=new JButton("工作结束返回主界面");
	//	b.setBounds(90, 150, 100, 60);
	//	b.setFont(new Font("",Font.PLAIN,7));
//		b1.setBounds(400, 150, 200, 100);
//		b1.setFont(new Font("",Font.PLAIN,15));
		b2.setBounds(100,150,200,100);
		b2.setFont(new Font("",Font.PLAIN,15));
//		c.add(b1);
	//	c.add(b);
		c.add(b2);
		c.setBackground(Color.WHITE);
		setResizable(false);
		setVisible(true);
		
//		b.addActionListener(new ActionListener() {
//			
//			@Override
//			public void actionPerformed(ActionEvent actionEvent) {
//				// TODO Auto-generated method stub
//				
//					// TODO Auto-generated method stub
//					QueryDoctor qd=new QueryDoctor();
//					String d_id = null;
//					ResultSet rs=qd.querydoctor(d_id);
//					QueryDoctorFr qdm=new QueryDoctorFr(rs,d_id);
//			}
//		});
		
//		b1.addActionListener(new ActionListener() {
//			
//			@Override
//			public void actionPerformed(ActionEvent actionEvent) {
//				// TODO Auto-generated method stub
//				new DoctorRegisterFr();
//			}
//		});
		b2.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent  actionEvent) {
				// TODO Auto-generated method stub
				new Login_2();
			}
		});
	}

}

15、Doctorlook

package his;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.cqcet.dao.QueryDepartment;
import com.cqcet.fram.QueryDeparMentsFram;

public class Doctorlook extends JFrame {
	String d_id=null;
	public Doctorlook(String username,String d_id){
		this.d_id=d_id;
		setTitle("教师主界面");
		
		setLayout(null);
		setBounds(600,300,800,600);
		//setBounds(100,100,800,600);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		
JPanel jp1=new JPanel();
jp1.setLayout(null);
jp1.setBounds(20, 20, 760, 560);
JLabel jl1=new JLabel("欢迎"+username+"老师登录学生成绩管理系统");
jl1.setBounds(150, 80, 500, 200);
jl1.setFont(new Font("",Font.PLAIN,30));
jp1.add(jl1);

JButton jb1=new JButton("请查看学生选课情况");
jb1.setFont(new Font("",Font.PLAIN,20));
jb1.setBounds(300, 250, 250, 60);
jp1.add(jb1);	
add(jp1);
setVisible(true);

jb1.addActionListener(new ActionListener(){

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		QueryDoctor qd=new QueryDoctor();
		ResultSet rs=qd.querydoctor(d_id);
		QueryDoctorFr qdm=new QueryDoctorFr(rs,d_id);
		
	}
	
});
}

}

16、DoctorRegister

package his;
import java.sql.Connection;  
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;  
import om.cqcet.com.DBUtile;

public class DoctorRegister {
	private String username;
	private String password;
	private String depart_id;
	private String course;
	
	
	public DoctorRegister(String username,String password,String course,String depart_id ){
		this.username=username;
		this.password=password;
		this.depart_id=depart_id;
		this.course=course;
	}
	public String register (){
		String ret=null;
		String sql="SELECT id FROM teacher WHERE username='"+username+"'and password = '"+password+"'";
		DBUtile dbu=new DBUtile();
		ResultSet rs=dbu.query(sql);
		try{
			while(rs.next())
				ret=rs.getString(1);	
			System.out.println(ret);
				
			}catch(SQLException e){
			e.printStackTrace();
			}
		return ret;
	}
		
	}





17、DoctorRegisterFr

package his;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.cqcet.dao.Login;
import com.cqcet.fram.P_Main;
import com.cqcet.fram.ReginsDoctor;


public class DoctorRegisterFr  extends JFrame{
	public DoctorRegisterFr (){
		setTitle("学生成绩管理系统—教师端");
		ImageIcon img = new ImageIcon("src/picture/a1.jpg");
		JLabel imgLabel = new JLabel(img);
		this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
		imgLabel.setBounds(0,0,800,500 );
		Container contain = this.getContentPane();
		((JPanel) contain).setOpaque(false); 
		setLayout(null);
		setBounds(600,300,800,600);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		Container c=getContentPane();
		JLabel l=new JLabel();
		JTextField jt=new JTextField();
		jt.setText("");
		JPasswordField jp=new JPasswordField();
		JButton b=new JButton("登录");
		JButton b1=new JButton("取消");
		JButton b2=new JButton("注册");
		jt.setBounds(80, 80, 200, 30);
		c.add(jt);
		jp.setBounds(80, 120, 200,30);
		c.add(jp);
		JLabel l1=new JLabel("Name:");
		JLabel l2=new JLabel("Password:");
		l1.setBounds(15, 75, 50, 50);
		l2.setBounds(15, 105, 80, 50);
		c.add(l1);
		c.add(l2);
		b.setBounds(90, 170, 80, 50);
		b.setFont(new Font("",Font.PLAIN,15));
		b1.setBounds(210, 170, 80, 50);
		b1.setFont(new Font("",Font.PLAIN,15));
		b2.setBounds(0,170,80,50);
		b2.setFont(new Font("",Font.PLAIN,15));
		c.add(b1);
		c.add(b);
		c.add(b2);
		c.setBackground(Color.WHITE);
		setResizable(false);
		setVisible(true);
		
		
		b.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent actionEvent) {
				// TODO Auto-generated method stub
			System.out.println("Value:"+"\t\t"+jt.getText());
			char a[]=jp.getPassword();
			String b=new String(a);
			String b1=new String(jt.getText());
			String b2=new String(jt.getText());
			System.out.println("password"+"\t"+b);
			System.err.println("----end----");
			
			
			DoctorRegister lg=new DoctorRegister(b1,b,null, b2);
			String d_id=lg.register();
			if((Integer.parseInt(d_id)>=1)){
				System.out.println("登录成功");
				setVisible(false);
				
				new Doctorlook(b1,d_id);//跳转
			}else{
				System.out.println("登录失败");
			}
			}
		});
		b1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent actionEvent) {
				// TODO Auto-generated method stub
				System.exit(0);
			}
		});
		b2.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent  actionEvent) {
				// TODO Auto-generated method stub
				new ReginsDoctor();
			}
		});
	}

}

18、HisTest

package his;



import java.sql.ResultSet;

import com.cqcet.fram.LoginJfram;

import com.cqcet.zhen.Doctorzhen;

import com.cqcet.zhen.QueryDoctorzhen;




public class HisTest {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
			
			new Login_2();
			

		
		}
		
}

19、Login_2 

package his;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.cqcet.fram.LoginJfram;
import com.cqcet.fram.P_Main;
import com.cqcet.fram.QueryDeparMentsFram;
import java.util.*;
	public class Login_2 extends JFrame implements ActionListener, ItemListener {
		JLabel usertype = new JLabel("请选择您的身份");
		ButtonGroup buttongroup = new ButtonGroup();
		JRadioButton yisheng = new JRadioButton("教师");
		JRadioButton huanzhe = new JRadioButton("学生");
		public Login_2() {
			super("欢迎来到学生成绩管理系统");
			JTextField text1 = new JTextField(18);
			JPasswordField text2 = new JPasswordField(18);
			ImageIcon img = new ImageIcon("src/picture/a2.jpg");
			JLabel imgLabel = new JLabel(img);
			this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
			imgLabel.setBounds(0,-10,800,600 );
			Container contain = this.getContentPane();
			((JPanel) contain).setOpaque(false); 
			setLayout(null);
			setBounds(600,300,800,600);
			setVisible(true);
			setResizable(false);
			setLayout(new FlowLayout(FlowLayout.CENTER, 15, 10));
			
			add(usertype);
			add(yisheng);
			add(huanzhe);

			buttongroup.add(yisheng);
			buttongroup.add(huanzhe);

			yisheng.addItemListener(this);
			huanzhe.addItemListener(this);

		}
		public void itemStateChanged(ItemEvent e) {
			if (e.getSource() == yisheng) {
				new DoctorRegisterFr();
				setVisible(false);
			} else if (e.getSource() == huanzhe) {
				new LoginJfram();
				setVisible(false);
			} 
			}
		public static void main(String args[]) {
			new Login_2();
		}
		@Override
		public void actionPerformed(ActionEvent arg0) {
			// TODO Auto-generated method stub
		}

	}

20、QueryDoctor

package his;

import java.sql.ResultSet;

import om.cqcet.com.DBUtile;

public class QueryDoctor {

	public ResultSet querydoctor(String d_id) {
		// TODO Auto-generated method stub
		ResultSet rs=null;
		
		DBUtile dbu=new DBUtile();
		String sql="select * from regestraion  where teacher_id='"+d_id +"'";
		rs=dbu.query(sql);
		
		return rs;
	}

}

21、QueryDoctorFr

package his;
import java.awt.Container;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import com.cqcet.dao.QueryDoctor;
import com.cqcet.zhen.Doctorzhen;
import om.cqcet.com.DBUtile;


public class QueryDoctorFr extends JFrame{
		JTable table=null;
		DefaultTableModel tableModel;
				
		private Object[][]data=null;
		ResultSet rs=null;
		Vector<Vector<Object>> dataVector=null;
		String d_id=null;		
		public QueryDoctorFr(ResultSet rs,String d_id){
			this.rs=rs;		
			setTitle("教师查询学生选课界面");
			ImageIcon img = new ImageIcon("src/picture/a3.jpg");
			JLabel imgLabel = new JLabel(img);
			this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
			imgLabel.setBounds(0,0,800,500 );
			Container contain = this.getContentPane();
			((JPanel) contain).setOpaque(false); 
			setLayout(null);
			//setBounds(100,100,800,600);
			setBounds(600,300,800,600);
			setDefaultCloseOperation(EXIT_ON_CLOSE);
			table=new JTable();
			tableModel=new DefaultTableModel();
			
			table.setModel(tableModel);
			JScrollPane scrollPane=new JScrollPane(table);
			scrollPane.setBounds(0, 0, 700, 450);
			this.add(scrollPane);
			this.setVisible(true);
			try{
				queryData();
			}catch(Exception e){
				
			}
		
		table.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent e){
				int index=table.getSelectedRow();
				String id=(String)table.getValueAt(index, 0);
				String sql="select * from teacher where depart_id="+id;
				DBUtile dbu=new DBUtile();
				ResultSet rs=dbu.query(sql);
				new Doctorzhen();
			}
		});}
		private void queryData()  throws Exception{
			// TODO Auto-generated method stub
			  System.out.println("just test!");
		        int count=0;
		        ResultSetMetaData rsmd=null;
		        
		        rsmd=rs.getMetaData();
		        count=rsmd.getColumnCount();
		        
		        for(int i=1; i<=count;i++){
		            tableModel.addColumn(rsmd.getColumnName(i));
		        }
		        String[] row=new String[count];
		        while(rs.next()){
		            for(int i =0;i<count;i++){
		                row[i]=rs.getString(i+1);
		            }
		            tableModel.addRow(row);}}}

22、DBUtile


package om.cqcet.com;

	import java.sql.*;

import com.mysql.jdbc.Connection;
	public class DBUtile {
		private java.sql.Connection conn;
		//做连接
		private Statement st;
		private ResultSet rs;
	    public  DBUtile(){
	    	try{
	    	Class.forName("com.mysql.jdbc.Driver");
	    	}catch(ClassNotFoundException e){
	    		e.printStackTrace();
	    	}
	    	try{
	    		conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/his1?characterEncoding=utf-8", "root","root");
	    	}catch(SQLException e){
	    		e.printStackTrace();
	    	}
	    	
	    		try {
					st=conn.createStatement();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	    
	    } 
	    public int  update(String sql){
	    	System.out.println(sql);
	    	int ret=-1;
	    	try{
	    		ret=st.executeUpdate(sql);
	    	}catch(SQLException e){
	    		e.printStackTrace();
	    	}
	    	return ret;
	    }
	    public ResultSet query(String sql){
	    	System.out.println(sql);
	    	try{
	    		rs=st.executeQuery(sql);
	    	}catch(SQLException e){
	    		e.printStackTrace();
	    	}
	    	return rs;
	    }
	    public void close(){
	    	if(rs!=null){
	    		try{
	    			rs.close();
	    		}catch(SQLException e){
	    			e.printStackTrace();
	    		}
	    	}
	    	if(st!=null){
	    		try{
	    			st.close();
	    		}catch(SQLException e){
	    			e.printStackTrace();
	    		}
	    	}
	    	if(conn!=null){
	    		try{
	    			conn.close();
	    		}catch(SQLException e){
	    			e.printStackTrace();
	    		}
	    	}
	    }
//		public static Connection getConnection() {
//			// TODO Auto-generated method stub
//			return null;
//		}
		// 获取数据库连接的静态方法
	    public static Connection getConnection() {
	        Connection conn = null;
	        try {
	            Class.forName("com.mysql.jdbc.Driver");
	            conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/his1?characterEncoding=utf-8", "root", "root");
	        } catch (ClassNotFoundException | SQLException e) {
	            e.printStackTrace();
	        }
	        return conn;
	    }

	    // 关闭数据库连接的静态
	    public static void closeConnection(Connection conn) {
	        if (conn != null) {
	            try {
	                conn.close();
	            } catch (SQLException e) {
	                e.printStackTrace();
	            }
	        }
	        }

	}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值