精华内容
下载资源
问答
  • java学生成绩管理系统

    2016-05-13 14:06:43
    用写的java学生成绩管理系统,很小
  • Java学生成绩管理系统

    万次阅读 多人点赞 2019-09-21 09:32:45
    目录 引言 开发环境 所用技术 项目目录 数据库设计 功能介绍 源码下载 更多优质练手项目 Java个人博客项目 JavaWeb练手项目ATM机 Java图书管理系统 Java电子发票管理系统 引言 这是当时刚学完SpringMVC、Spring-Data...

    目录

    引言

    开发环境

    所用技术

    项目目录

    数据库设计

    功能介绍

    源码下载


    更多优质练手项目

    Java个人博客项目

    JavaWeb练手项目ATM机

    Java图书管理系统

    Java电子发票管理系统

    引言

    这是当时刚学完SpringMVC、Spring-Data-Jpa和Hibernate后台框架写的一个项目。一是月考核的项目,二是刚学完这些框架,需要练习一下,总结一下。这也是我用框架写的第一个项目,所以有很多不足之处,希望大家可以指出,一起交流学习。

    开发环境

    开发工具:Eclipse、jdk1.8、Tomcat9.0

    数据库:MySQL5.5

    所用技术

    前端:BootStrap、JQuery、HTML+CSS、Ajax、Jstl

    后端:SpringMVC、Spring-Data-Jpa、Interceptor拦截器

    项目管理:Maven

    没学过Spring-Data-Jpa的小伙伴可以先了解一下Spring-Data-Jpa入门篇

    项目目录

    项目总共有三个配置文件applicationContext.xml、spring-mvc.xml、web.xml。分别配置链接数据库信息,拦截器的配置和MVC的配置,如果有需要改数据库链接等配置的可以自行更改,配置文件中都有详细的注释。index.jsp为登录页面,也是首页。

    数据库设计

    整个项目总共涉及到了六张表,如下。

    mcy_teacher老师表

    mcy_student学生表

    mcy_class班级表。

    mcy_grade成绩表。

    mcy_course课程表。

    mcy_admin管理员表。

    表结构都在这里了,大家也可以看实体类中对应的字段。

    功能介绍

    项目首页,点击登录,登录页面是弹框显示的。

    角色

    该系统分为三个角色:管理员、老师和学生。

    管理员

    登录成功,页面和首页一样,菜单是根据登录者的身份去判断显示该角色对应的菜单。

    管理员主要功能有:老师管理,班级管理,学生管理,课程管理,修改密码等功能

    由于当时还没有学习前端框架,自己看了一下BootStrap,所以只是页面样式采用了BootStrap的样式,没有使用BootStrapTable。管理员需要先添加班级,才能添加对应班级的学生。这里需要注意的是,老师是代课老师,所以添加班级中辅导员,不一定是老师管理中的老师,管理员可以对学生和老师的账号密码重置,重置后的密码为123456。

    部分功能展示。

    学生管理,可以更改下拉列表,显示对应班级的学生,还可以对其学生密码重置,重置后的密码为123456。

    老师

    登录成功页面都是一样的,菜单根据登录者的身份去判断,显示对应的菜单。

    老师主要的功能有:成绩录入和修改,学生管理,修改密码等功能。其中学生管理和管理员一样,老师可以根据班级和课程录入班级学生的成绩,课程是有管理员新增和修改的。修改成绩是感觉班级和姓名对学生所有课程成绩的修改,老师可以对学生的账号密码重置,重置后的密码为123456。

    功能展示。

    录入成绩。

    修改学生成绩。

    学生

    学生主要功能:查看班级成绩,查看班级成员,查看个人成绩等

    功能展示。

    源码下载

    【注】源码只用于交流学习,不能用于任何其他目的。

    上面是项目的一些描述,如果有需要的下载项目代码的小伙伴下面是码云下载地址。

    码云地址:https://gitee.com/machaoyin/performance_management

    如果你对学java还很迷茫,这里分享你一套Java学习路线https://blog.csdn.net/qq_40205116/article/details/89944370

    如果对你有帮助,点赞关注一下呗^_^,留下你的足迹。

    展开全文
  • Java 学生成绩管理系统

    万次阅读 多人点赞 2018-01-13 00:42:37
    教学管理系统很适合初学者对于所学语言的练习。本文是javaSE 中用文件流写的,这个也可以用数据库写。分析这个项目有 1.学生 2.老师 3.教务人员 4.管理员四个角色分别担任不同的任务。1.学生 有属性 id, 密码,性别...

    教学管理系统很适合初学者对于所学语言的练习。本文是javaSE 中用文件流写的,这个也可以用数据库写。

    分析

    这个项目有 1.学生 2.老师 3.教务人员 4.管理员四个角色分别担任不同的任务。

    1.学生 有属性 id, 密码,性别,年龄,和一个存放成绩的集合(因为一个学生可能会有多个科目,所以用集合来存放学生的所学科目)。
    2.老师 有属性 id,密码,性别,年龄,和一成绩类的对象(考虑到老师只教授一科目,所以在老师类中实现一个科目类的对象)。
    3.教务人员 有属性 id,密码(教务人员没有考虑自身的信息,主要对老师和学生的管理)。
    4.管理员 对学生老师和教务人员进行帐号注册(例如学校的教学网第一次登录不需要注册直接用学号登录然后改密码,这样防止外人注册进入到系统)
    只有一个系统管理员,用来添加学生,教师和教务人员帐号,方便学习这里帐号id为111,密码为111。
    还要有科目类 有属性 科目名,科目编号,科目分数。
    这里写图片描述

    代码

    基本类创建

    1.学生类

    package com.file;
    
    import java.io.Serializable;
    import java.util.ArrayList;
    
    public class Student implements Serializable {
        private String id = null;   //设为私有属性,区分老师类的属性
        private String password = null;
        private String name = null;
        private String age = null;
        private String sex = null;
    
        public ArrayList<Course> arr_course = new ArrayList<Course>();
        public String getId() {
            return id;
        }
        public void setId(String id) {
            this.id = id;
        }
        public Student() {
            super();
        }
        public Student(String id, String password) {
            super();
            this.id = id;
            this.password = password;
        }
        public Student(String id, String password, String name, String age,
                String sex) {
            super();
            this.id = id;
            this.password = password;
            this.name = name;
            this.age = age;
            this.sex = sex;
        }
        public String getPassword() {
            return password;
        }
        public void setPassword(String password) {
            this.password = password;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getAge() {
            return age;
        }
        public void setAge(String age) {
            this.age = age;
        }
        public String getSex() {
            return sex;
        }
        public void setSex(String sex) {
            this.sex = sex;
        }
    }
    

    2.老师类

    package com.file;
    
    import java.io.Serializable;
    
    public class Teacher  implements Serializable{
    
        private String id = null;
        private String name = null;
        private String password = null;
        private String age = null;  
        private String sex = null;
        private Course teaching_course = null;
    
        public Teacher(String id, String password) {
            super();
            this.id = id;
            this.password = password;
        }
        @Override
        public String toString() {
            return "Teacher [id=" + id + ", name=" + name + ", password="
                    + password + ", age=" + age + ", sex=" + sex
                    + ", teaching_course=" + teaching_course + "]";
        }
        public Teacher(String id, String name, String password, String age,
                String sex, Course teaching_course) {
            super();
            this.id = id;
            this.name = name;
            this.password = password;
            this.age = age;
            this.sex = sex;
            this.teaching_course = teaching_course;
        }
        public Teacher() {
            super();
            // TODO Auto-generated constructor stub
        }
        public String getId() {
            return id;
        }
        public void setId(String id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getPassword() {
            return password;
        }
        public void setPassword(String password) {
            this.password = password;
        }
        public String getAge() {
            return age;
        }
        public void setAge(String age) {
            this.age = age;
        }
        public String getSex() {
            return sex;
        }
        public void setSex(String sex) {
            this.sex = sex;
        }
    
        public Course getTeaching_course() {
            return teaching_course;
        }
        public void setTeaching_course(Course teaching_course) {
            this.teaching_course = teaching_course;
        }
    }
    

    3.教务人员类

    package com.file;
    
    import java.io.Serializable;
    
    public class Manage implements Serializable{
        private String id = null;
        private String name = null;
        private String password = null;
        public Manage() {
            super();
            // TODO Auto-generated constructor stub
        }
        public Manage(String id, String name, String password) {
            super();
            this.id = id;
            this.name = name;
            this.password = password;
        }
        public Manage(String id, String password) {
            super();
            this.id = id;
            this.password = password;
        }
        @Override
        public String toString() {
            return "Manage [id=" + id + ", name=" + name + ", password=" + password
                    + "]";
        }
        public String getId() {
            return id;
        }
        public void setId(String id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getPassword() {
            return password;
        }
        public void setPassword(String password) {
            this.password = password;
        }
    
    }
    

    4.科目类

    package com.file;
    
    import java.io.Serializable;
    
    public class Course implements Serializable{
    
        public String courseId = null;  //课程编号
        public String courseName = null;  //课程名
        public String courseMark = null;  //课程分数
    
        public String getCourseId() {
            return courseId;
        }
        public void setCourseId(String courseId) {
            this.courseId = courseId;
        }
        public String getCourseName() {
            return courseName;
        }
        public Course(String courseName) {
            super();
            this.courseName = courseName;
        }
        public void setCourseName(String courseName) {
            this.courseName = courseName;
        }
        public String getCourseMark() {
            return courseMark;
        }
        public void setCourseMark(String courseMark) {
            this.courseMark = courseMark;
        }
        public Course(String courseId, String courseName, String courseMark) {
            super();
            this.courseId = courseId;
            this.courseName = courseName;
            this.courseMark = courseMark;
        }
        public Course() {
            super();
            // TODO Auto-generated constructor stub
        }
        public int searchCourse(){  
            return 0;
        }
        @Override
        public String toString() {
            return "Course [courseId=" + courseId + ", courseName=" + courseName
                    + ", courseMark=" + courseMark + "]";
        }
    
    }
    

    实现输入输出文件流

    在实现时用集合来实现所以对学生老师教务人员创建三个集合

    package com.file;
    
    import java.util.ArrayList;
    
    public class DB {
        public static ArrayList<Student> arrStu = new ArrayList<Student>();//学生
        public static ArrayList<Teacher> arrTea = new ArrayList<Teacher>();//老师
        public static ArrayList<Manage> arrMan= new ArrayList<Manage>();//教务人员
    }
    

    为了方便使用给学生老师和教务人员各建一个输入输出类,代码都类似。

    1.学生输入输出流流

    package com.file;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
    
    public class IOStreamStudent {
        public static File file = new File("stu.txt");
    
        public static void writeToFile() {
            FileOutputStream fo = null;
            ObjectOutputStream objout = null;
            try {
                fo = new FileOutputStream(file);
                objout = new ObjectOutputStream(fo);
                objout.writeObject(DB.arrStu);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    objout.flush();
                    objout.close(); 
                    fo.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("Write Student to File" + " " + file);
        }
    
        @SuppressWarnings({ "resource", "unchecked" })
        public static ArrayList<Student> readFromFile(){
            ArrayList<Student> arr = null;
            ObjectInputStream objin = null;
            FileInputStream fin = null;
            try{
                fin = new FileInputStream(file);
                objin = new ObjectInputStream(fin);
                arr = (ArrayList<Student>) objin.readObject();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } 
            return arr;
        }
    
    }
    

    2.老师输入输出流

    package com.file;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
    
    public class IOStreamTeacher {
        public static File file = new File("tea.txt");
    
        public static void writeToFile() {
            FileOutputStream fo = null;
            ObjectOutputStream objout = null;
            try {
                fo = new FileOutputStream(file);
                objout = new ObjectOutputStream(fo);
                objout.writeObject(DB.arrTea);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    objout.flush();
                    objout.close(); 
                    fo.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("Write Teacher to File" + " " + file);
        }
    
        @SuppressWarnings({ "resource", "unchecked" })
        public static ArrayList<Teacher> readFromFile(){
            ArrayList<Teacher> arr = null;
            ObjectInputStream objin = null;
            FileInputStream fin = null;
            try{
                fin = new FileInputStream(file);
                objin = new ObjectInputStream(fin);
                arr = (ArrayList<Teacher>) objin.readObject();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } 
            return arr;
        }
    
    }
    
    

    3.教务人员输入输出

    package com.file;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
    
    public class IOStreamManage {
        public static File file = new File("manage.txt");
    
        public static void writeToFile() {
            FileOutputStream fo = null;
            ObjectOutputStream objout = null;
            try {
                fo = new FileOutputStream(file);
                objout = new ObjectOutputStream(fo);
                objout.writeObject(DB.arrMan);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    objout.flush();
                    objout.close(); 
                    fo.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("Write Manage to File" + " " + file);
        }
    
        @SuppressWarnings({ "resource", "unchecked" })
        public static ArrayList<Manage> readFromFile(){
            ArrayList<Manage> arr = null;
            ObjectInputStream objin = null;
            FileInputStream fin = null;
            try{
                fin = new FileInputStream(file);
                objin = new ObjectInputStream(fin);
                arr = (ArrayList<Manage>) objin.readObject();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } 
            return arr;
        }
    
    }
    

    在当前项目下创建stu.txt tea.txt manage.txt三个文件用来保存数据。

    登录界面

    因为是只有管理员才能注册新的用户,所以此页面没有注册按钮,需要注册时点击管理员按钮进入Register类进行注册。
    如果要更改为每个随意注册只需添加注册按钮和相应的监听,然后转到Register类即可。

    package com.file;
    
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.Iterator;
    
    import javax.swing.ButtonGroup;
    import javax.swing.Icon;
    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.JRadioButton;
    import javax.swing.JTextField;
    
        public class Login extends JFrame{
            static String administration_id = "111";
            static String administration_password = "111";
            String zhiwu;
            JFrame jf;
            JLabel jl_id,jl_password,jl3;
            public static JTextField jt_id,jt_password;
            JPanel jp1,jp2,jp3,jp4,jp_group,jp_img;
            JButton jb_login;
            JRadioButton radioButton_student,radioButton_teacher,radioButton_manage,radioButton_administration;
            ButtonGroup group;
            ImageIcon img = null;
            public Login(){
                jf = new JFrame();
                jf.setSize(500,700);
                jf.setLocation(500,100);
                jf.setDefaultCloseOperation(EXIT_ON_CLOSE);
                jf.setLayout(new GridLayout(6,2));
    
                Icon img = new ImageIcon("tu1.gif");
                jp_img = new JPanel();
                jp_img.add(new JLabel(img));            
    
                jl_id = new JLabel("用户名");
                jt_id = new JTextField(15);
                jp1  =new JPanel();
                jp1.add(jl_id);
                jp1.add(jt_id);
                jl_password = new JLabel("密码");
                jt_password = new JTextField(15);
                jp2 = new JPanel();
                jp2.add(jl_password);
                jp2.add(jt_password);
                jl3 = new JLabel("学生管理系统");
                jp3 = new JPanel();
                jp3.add(jl3);
    
                jp_group = new JPanel();
                radioButton_student = new JRadioButton("学生");
                jp_group.add(radioButton_student);
                radioButton_teacher = new JRadioButton("老师");
                jp_group.add(radioButton_teacher);
                radioButton_manage = new JRadioButton("教务");
                jp_group.add(radioButton_manage);
                radioButton_administration = new JRadioButton("管理员");
                jp_group.add(radioButton_administration);
                group = new ButtonGroup();  //创建按钮组保证3个按钮一次只能按下一个
                group.add(radioButton_student);
                group.add(radioButton_teacher);
                group.add(radioButton_manage);
                group.add(radioButton_administration);
    
                jb_login = new JButton("登录");
                jp4 = new JPanel();
                jp4.add(jb_login);
    
                jf.add(jp_img);
                jf.add(jp3);
                jf.add(jp1);
                jf.add(jp2);
                jf.add(jp_group);
                jf.add(jp4);
                jf.setVisible(true);
                //登录按钮监听
            jb_login.addActionListener(new ActionListener() {
                @SuppressWarnings("unused")
                public void actionPerformed(ActionEvent e) {
                    boolean flow = true;
                    //学生
                    if (radioButton_student.isSelected()) {
                        if (IOStreamStudent.file.length() == 0) {
                            JOptionPane.showMessageDialog(null, "用户名不存在", "提示信息",JOptionPane.ERROR_MESSAGE);
                        } else {
                            ArrayList<Student> arr = IOStreamStudent.readFromFile();
                            Iterator<Student> it = arr.iterator();
                            while (it.hasNext()) {
                                Student newstu = it.next();
                                if (newstu.getId().equals(jt_id.getText())) {
                                    if (newstu.getPassword().equals(jt_password.getText())) {
                                        new StudentLogin(newstu);                                   
                                    } else {
                                        JOptionPane.showMessageDialog(null,"密码或用户名错误");                                 
                                    }
                                    flow = false;
                                } 
                            }if(flow){
                                JOptionPane.showMessageDialog(null, "用户名不存在");
                            }
    
                        }
                    }
    
                    //老师
                    if (radioButton_teacher.isSelected()) {
                        if (IOStreamTeacher.file.length() == 0) {
                            JOptionPane.showMessageDialog(null, "用户名不存在", "提示信息",JOptionPane.ERROR_MESSAGE);
                        } else {
                            ArrayList<Teacher> arr = IOStreamTeacher.readFromFile();
                            Iterator<Teacher> it = arr.iterator();
                            while (it.hasNext()) {
                                Teacher newtea = it.next();
                                if (newtea.getId().equals(jt_id.getText())) {
                                    if (newtea.getPassword().equals(jt_password.getText())) {
                                        new TeacherLogin(newtea);
                                    } else {
                                        JOptionPane.showMessageDialog(null,"密码或用户名错误");
                                    }
                                    flow = false;
                                }
                            }
                            if (flow) {
                                JOptionPane.showMessageDialog(null, "用户名不存在");
                            }
                        }
                    }
                    //教务
                    if (radioButton_manage.isSelected()) {
                        if(IOStreamManage.file.length() == 0){
                            JOptionPane.showMessageDialog(null, "用户名不存在","提示信息",JOptionPane.ERROR_MESSAGE);
                        }else{                      
                            ArrayList<Manage> arr = IOStreamManage.readFromFile();
                            Iterator<Manage> it = arr.iterator();
                            while (it.hasNext()) {
                                Manage newman = it.next();
                                if (newman.getId().equals(jt_id.getText())) {
                                    if (newman.getPassword().equals(jt_password.getText())) {
                                        new ManageLogin(newman);                                        
                                    } else {
                                        JOptionPane.showMessageDialog(null, "密码或用户名错误");
                                    }
                                    flow = false;
                                }
                            }if(flow){
                                JOptionPane.showMessageDialog(null, "用户名不存在");
                            }
                        }
                    }
                    //系统管理员
                    if (radioButton_administration.isSelected()) {
                        if (administration_id.equals(jt_id.getText())) {
                            if (administration_password.equals(jt_password.getText())) {
                                new Register();
                            } else {
                                JOptionPane.showMessageDialog(null, "密码错误");
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "请重新登录");
                        }
    
                    }
                }
            });
            }
            //学生查寻返回元素下标
            public static int searchStudent(){
                int index = -1;
                String userid = jt_id.getText();
                if(IOStreamStudent.file.length() == 0){
                    return index;
                }else{
                    ArrayList<Student> arr  = IOStreamStudent.readFromFile();
                    for(int i=0; i<arr.size(); i++){
                        if(userid.equals(arr.get(i).getId())){
                            index = i;
                            return index;
                        }
                    }
                }
                return index;
            }
            //老师查询返回元素下标
            public static int searchTeacher(){
                int index = -1;
                String userid = jt_id.getText();
                if(IOStreamTeacher.file.length() == 0){
                    return index;
                }else{
                    ArrayList<Teacher> arr  = IOStreamTeacher.readFromFile();
                    for(int i=0; i<arr.size(); i++){
                        if(userid.equals(arr.get(i).getId())){
                            index = i;
                            return index;
                        }
                    }
                }
                return index;
            }
            //管理员查询返回下标
            public static int searchManage(){
                int index = -1;
                String userid = jt_id.getText();
                if(IOStreamManage.file.length() == 0){
                    return index;
                }else{
                    ArrayList<Manage> arr  = IOStreamManage.readFromFile();
                    for(int i=0; i<arr.size(); i++){
                        if(userid.equals(arr.get(i).getId())){
                            index = i;
                            return index;
                        }
                    }
                }
                return index;
            }
    }
    

    这里写图片描述

    注册页面

    在登录页面点击管理员按钮后进入到此页面,进行创建角色的创建。

    package com.file;
    
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Iterator;
    
    import javax.swing.ButtonGroup;
    import javax.swing.Icon;
    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.JRadioButton;
    import javax.swing.JTextField;
    
    public class Register {
        JFrame jf;
        JLabel jl_id, jl_password, jl_age, jl_sex, jl5;
        JTextField jt_id, jt_password, jt_age, jt_sex;
        JPanel jp1, jp2, jp3, jp4, jp5, jp6, jp_group, jp_img;
        JButton jb1;
        ButtonGroup group;
        JRadioButton radioButton_student, radioButton_teacher, radioButton_manage;
    
        public Register() {
            jf = new JFrame("注册界面");
            jf.setSize(500, 700);
            jf.setLocation(1300,100);
            jf.setVisible(true);
            jf.setLayout(new GridLayout(7, 2));
    
            Icon img = new ImageIcon("tu1.gif");
            jp_img = new JPanel();
            jp_img.add(new JLabel(img));
    
            jl_id = new JLabel("用户名");
            jt_id = new JTextField(15);
            jp1 = new JPanel();
            jp1.add(jl_id);
            jp1.add(jt_id);
            jl_password = new JLabel("密码");
            jt_password = new JTextField(15);
            jp2 = new JPanel();
            jp2.add(jl_password);
            jp2.add(jt_password);
    
            jp_group = new JPanel();
            radioButton_student = new JRadioButton("学生");
            jp_group.add(radioButton_student);
            radioButton_teacher = new JRadioButton("老师");
            jp_group.add(radioButton_teacher);
            radioButton_manage = new JRadioButton("教务");
            jp_group.add(radioButton_manage);
            group = new ButtonGroup();
            group.add(radioButton_student);
            group.add(radioButton_teacher);
            group.add(radioButton_manage);
    
            jb1 = new JButton("完成");
            jp5 = new JPanel();
            jp5.add(jb1);
            jl5 = new JLabel("注册成功");
            jp6 = new JPanel();
            jf.add(jp_img);
            jf.add(jp1);
            jf.add(jp2);
            jf.add(jp_group);
            jf.add(jp5);
            jf.add(jp6);
            jb1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    //学生
                    if (radioButton_student.isSelected()) {
                        Student stu = new Student(jt_id.getText(), jt_password
                                .getText());
                        if (IOStreamStudent.file.length() == 0) {
                            DB.arrStu.add(stu);
                            IOStreamStudent.writeToFile();
                            jp6.add(jl5);
                            jf.setVisible(true);
                            jt_id.setText("");
                            jt_password.setText("");
                        } else {
                            DB.arrStu.clear();
                            DB.arrStu = IOStreamStudent.readFromFile();
                            Iterator<Student> it = DB.arrStu.iterator();
                            boolean flag = true;
                            while (it.hasNext()) {
                                Student newstu = it.next();
                                if (newstu.getId().equals(jt_id.getText())) {
                                    flag = false;
                                    JOptionPane.showMessageDialog(null,
                                            "此用户名已存在,请重新输入");
                                }
                            }
                            if (flag) {
                                if (!(jt_id.getText().isEmpty() || jt_password
                                        .getText().isEmpty())) {
                                    DB.arrStu.add(stu);
                                    IOStreamStudent.writeToFile();
                                    jp6.add(jl5);
                                    jf.setVisible(true);
                                    jt_id.setText("");
                                    jt_password.setText("");
                                } else {
                                    JOptionPane.showMessageDialog(null,
                                            "密码,用户名不能为空");
                                }
                            }
                        }
                    }
                    //老师
                    if (radioButton_teacher.isSelected()) {
                        Teacher tea = new Teacher(jt_id.getText(), jt_password
                                .getText());
                        if (IOStreamTeacher.file.length() == 0) {
                            DB.arrTea.add(tea);
                            IOStreamTeacher.writeToFile();
                            jp6.add(jl5);
                            jf.setVisible(true);
                            jt_id.setText("");
                            jt_password.setText("");
                        } else {
                            DB.arrTea.clear();
                            DB.arrTea = IOStreamTeacher.readFromFile();
                            Iterator<Teacher> it = DB.arrTea.iterator();
                            boolean flag = true;
                            while (it.hasNext()) {
                                Teacher newtea = it.next();
                                if (newtea.getId().equals(jt_id.getText())) {
                                    flag = false;
                                    JOptionPane.showMessageDialog(null,
                                            "此用户名已存在,请重新输入");
                                }
                            }
                            if (flag) {
                                if (!(jt_id.getText().isEmpty() || jt_password
                                        .getText().isEmpty())) {
                                    DB.arrTea.add(tea);
                                    IOStreamTeacher.writeToFile();
                                    jp6.add(jl5);
                                    jf.setVisible(true);
                                    jt_id.setText("");
                                    jt_password.setText("");
                                } else {
                                    JOptionPane.showMessageDialog(null,
                                            "密码,用户名不能为空");
                                }
    
                            }
                        }
    
                    }
                    //管理员
                    if (radioButton_manage.isSelected()) {
                        Manage man = new Manage(jt_id.getText(), jt_password
                                .getText());
                        if (IOStreamManage.file.length() == 0) {
                            DB.arrMan.add(man);
                            IOStreamManage.writeToFile();
                            jp6.add(jl5);
                            jf.setVisible(true);
                            jt_id.setText("");
                            jt_password.setText("");
                        } else {
                            DB.arrMan.clear();
                            DB.arrMan = IOStreamManage.readFromFile();
                            Iterator<Manage> it = DB.arrMan.iterator();
                            boolean flag = true;
                            while (it.hasNext()) {
                                Manage newman = it.next();
                                if (newman.getId().equals(jt_id.getText())) {
                                    flag = false;
                                    JOptionPane.showMessageDialog(null,
                                            "此用户名已存在,请重新输入");
                                }
                            }
                            if (flag) {
                                if (!(jt_id.getText().isEmpty() || jt_password
                                        .getText().isEmpty())) {
                                    DB.arrMan.add(man);
                                    IOStreamManage.writeToFile();
                                    jp6.add(jl5);
                                    jf.setVisible(true);
                                    jt_id.setText("");
                                    jt_password.setText("");
                                } else {
                                    JOptionPane.showMessageDialog(null,
                                            "密码,用户名不能为空");
                                }
    
                            }
                        }
    
                    }
                }
    
            });
        }
    }

    这里我们注册学生1,老师1,教务1,密码都是1
    这里写图片描述

    显示界面

    每个角色的显示界面不一样所以创建3个类,显示界面里包括了需要的内容。

    1.学生的显示界面 StudentLogin

    创建菜单选项,下设信息,成绩。

    package com.file;
    
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.Iterator;
    
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextField;
    import javax.swing.ListSelectionModel;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.JTableHeader;
    
    public class StudentLogin {
    
        JFrame jf;
        JLabel jl_name, jl11, jl_age, jl21, jl_sex, jl31, jl_ReviseOK,jl_old_password,jl_new_password1,jl_new_password2,jl_inpassword_err;
        JTextField jt_name, jt_age, jt_sex;
        JPasswordField jp_old_password,jpassword1,jpassword2;
        JPanel jp1, jp2, jp3, jp4, jp_jb, jp_img,jp_scroll,jp_center;
        JButton jb,jb_revise_password;
        static JTable table;
        JScrollPane scrollPane;
        static DefaultTableModel model;
         JMenuBar jmb;
         JMenuItem jmb1find,jmb2find,jmb1revisePassword;
    
        public StudentLogin(final Student stu) {
    
            jf = new JFrame("欢迎 " + stu.getId() + " 同学,你好!");
            jf.setSize(1000, 700);
            jf.setLocation(800, 100);
            jf.setLayout(new BorderLayout(0,0));
            Icon img = new ImageIcon("tu2.jpg");
            jf.add(new JLabel(img),BorderLayout.NORTH);
    
            jmb = new JMenuBar(); //创建菜单
            jf.setJMenuBar(jmb);    
            JMenu jmb1 = new JMenu("个人信息");
            jmb.add(jmb1);
            jmb1find = new JMenuItem("查看个人信息");
            jmb1.add(jmb1find); 
            jmb1revisePassword = new JMenuItem("修改账户密码");
            jmb1.add(jmb1revisePassword);   
            JMenu jmb2 = new JMenu("我的成绩");
            jmb.add(jmb2);
            jmb2find = new JMenuItem("查看所有");
            jmb2.add(jmb2find);
    
            jp_center = new JPanel();//中心的面板
            jf.setVisible(true);
    
            jmb1find.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    jp_center.removeAll();
                    jp_center.setLayout(new GridLayout(7,2));
                    jf.add(jp_center,BorderLayout.CENTER);
    
                    jl_name = new JLabel("姓名");
                    jt_name = new JTextField(20);
                    jt_name.setText(stu.getName());
                    jp1 = new JPanel();
                    jp1.add(jl_name);
                    jp1.add(jt_name);
                    jl_age = new JLabel("年龄");
                    jt_age = new JTextField(20);
                    jt_age.setText(stu.getAge());
                    jp2 = new JPanel();
                    jp2.add(jl_age);
                    jp2.add(jt_age);
                    jl_sex = new JLabel("性别");
                    jt_sex = new JTextField(20);
                    jt_sex.setText(stu.getSex());
                    jp3 = new JPanel();
                    jp3.add(jl_sex);
                    jp3.add(jt_sex);
                    jl_ReviseOK = new JLabel("修改成功");
                    jp4 = new JPanel();
                    jb = new JButton("修改信息");
                    jp_jb = new JPanel();
                    jp_jb.add(jb);
    
                    jp_center.add(jp1);
                    jp_center.add(jp2);
                    jp_center.add(jp3);
                    jp_center.add(jp_jb);
                    jp_center.add(jp4);
                    jf.setVisible(true);
    
                    jb.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
    
                            stu.setName(jt_name.getText());
                            stu.setAge(jt_age.getText());
                            stu.setSex(jt_sex.getText());
                            Student newstu = stu;
                            DB.arrStu.clear();
                            DB.arrStu = IOStreamStudent.readFromFile();
                            DB.arrStu.set(Login.searchStudent(), newstu);
                            IOStreamStudent.writeToFile();
                            jp4.add(jl_ReviseOK);
                            jf.setVisible(true);
                        }
                    });
                }
            });
            jmb1revisePassword.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    jp_center.removeAll();
                    jp_center.setLayout(new GridLayout(6,2));
                    jf.add(jp_center, BorderLayout.CENTER);
                    jl_old_password = new JLabel("原密码");
                    jp_old_password = new JPasswordField(20);
                    jl_new_password1 = new JLabel("新密码");
                    jpassword1 = new JPasswordField(20);
                    jl_new_password2 = new JLabel("再次输入新密码");
                    jpassword2 = new JPasswordField(20);
                    jb_revise_password = new JButton("保存");
                    jl_inpassword_err = new JLabel("密码输入错误,请重新输入");
                    jl_inpassword_err.setForeground(Color.red);
                    jl_inpassword_err.setFont(new Font("宋体",Font.ITALIC,16));
                    JPanel jp1 = new JPanel();
                    JPanel jp2 = new JPanel();
                    JPanel jp3 = new JPanel();
                    final JPanel jp4 = new JPanel();
                    final JPanel jp5 = new JPanel();
                    JPanel jp_jb = new JPanel();
                    jp1.add(jl_old_password);
                    jp1.add(jp_old_password);
                    jp_center.add(jp1);
                    jp2.add(jl_new_password1);
                    jp2.add(jpassword1);
                    jp_center.add(jp2);
                    jp3.add(jl_new_password2);
                    jp3.add(jpassword2);
                    jp_center.add(jp3);
                    jp_center.add(jp4);
                    jp_jb.add(jb_revise_password);
                    jp_center.add(jp_jb);
                    jp_center.add(jp5);
                    jf.setVisible(true);
    
    
                    jb_revise_password.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if (String.valueOf(jp_old_password.getPassword()).equals(stu.getPassword())
                                    && (!(String.valueOf(jpassword2.getPassword())).equals(""))
                                    && ((String.valueOf(jpassword1.getPassword())).equals(String.valueOf(jpassword2.getPassword())))) {
                                stu.setPassword(String.valueOf(jpassword2.getPassword()));
                                Student newstu = stu;
                                DB.arrStu.clear();
                                DB.arrStu = IOStreamStudent.readFromFile();
                                DB.arrStu.set(Login.searchStudent(), newstu);
                                IOStreamStudent.writeToFile();
                                jp5.removeAll();
                                jp5.add(new JLabel("修改密码成功"));
                                jf.setVisible(true);
                            } else {
                                jp4.removeAll();
                                jp4.add(jl_inpassword_err);
                                jf.setVisible(true);
                            }
                        }
                    });     
                }
            });
    
            jmb2find.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("查看所有成绩");
                    jp_center.removeAll();
                    jp_center.setLayout(new GridLayout());
                    scrollPane = new JScrollPane();
                    jp_center.add(scrollPane);
                    jf.add(jp_center, BorderLayout.CENTER);
    
                    table = new JTable(); //创建一个表显示数据
                    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                    table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
                    table.setRowHeight(30);
                    JTableHeader header = table.getTableHeader(); // 获取 JTable 的头的对象
                    header.setFont(new Font("微软雅黑", Font.PLAIN, 16));
                    header.setPreferredSize(new Dimension(header.getWidth(), 35)); // 设置此组件的首选大小
                    scrollPane.setViewportView(table);
                    model = (DefaultTableModel) table.getModel();
                    model.setColumnIdentifiers(new Object[] { "课程编号", "课程名", "成绩","任课老师" });
                    CourseManage.findOneStudentAllCourseMark(stu);
                    jf.setVisible(true);
    
                }
            });
        }
    
    }
    

    看图,顺便把学生信息修改。

    这里写图片描述

    这里成绩是没有的,因为老师还没有分配科目。

    这里写图片描述

    2.老师的显示界面

    老师这里包含了个人信息显示和修改,修改学生成绩和查看所有学生成绩

    package com.file;
    
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextField;
    import javax.swing.ListSelectionModel;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.JTableHeader;
    
    public class TeacherLogin {
    
        static JFrame jf;
        JLabel jl_name,jl11,jl_age,jl21,jl_sex,jl31,jl4,jl_course,jl_old_password,jl_new_password1,jl_new_password2,jl_inpassword_err;
        JTextField jt_name,jt_age,jt_sex;
        JPasswordField jp_old_password,jpassword1,jpassword2;
        JPanel jp1,jp2,jp3,jp4,jp_jb;
        static JPanel jp_center,jp_south;
        JPanel jp_course;
        JButton jb,jb_revise,jb_revise_password;
        static JScrollPane scrollPane;
        static JTable table;
        static DefaultTableModel model;
        JMenuBar jmb;
        JMenuItem jmb1find,jmb2find,jmb2revise,jmb1revisePassword;
        JMenu jmb1,jmb2;
    
        public TeacherLogin(){}
    
        public TeacherLogin(final Teacher tea){ 
    
            jf = new JFrame(tea.getId()+" 老师,您好!");
            jf.setSize(1000,700);
            jf.setLocation(800,100);
            jf.setLayout(new BorderLayout(0,0));
            Icon img = new ImageIcon("tu2.jpg");
            JLabel jl = new JLabel(img);
            jf.add(jl,BorderLayout.NORTH);  
    
            jmb = new JMenuBar();
            jf.setJMenuBar(jmb);    
            JMenu jmb1 = new JMenu("个人信息");
            jmb.add(jmb1);
            jmb1find = new JMenuItem("查看个人信息");
            jmb1.add(jmb1find);
            jmb1revisePassword = new JMenuItem("修改账户密码");
            jmb1.add(jmb1revisePassword);   
            JMenu jmb2 = new JMenu("学生成绩");
            jmb.add(jmb2);
            jmb2find = new JMenuItem("查看所有");
            jmb2.add(jmb2find);
            jmb2revise = new JMenuItem("修改成绩");
            jmb2.add(jmb2revise);
    
            jp_center = new JPanel();
            jp_south = new JPanel();
            jf.setVisible(true);
    
            //查看并修改个人信息
            jmb1find.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    jp_center.removeAll();
                    jp_center.setLayout(new GridLayout(7,2));
                    jf.add(jp_center,BorderLayout.CENTER);
                    jl_name = new JLabel("姓名");
                    jt_name = new JTextField(20);
                    jt_name.setText(tea.getName());
                    jp1  =new JPanel();
                    jp1.add(jl_name);
                    jp1.add(jt_name);
                    jl_age = new JLabel("年龄");
                    jt_age = new JTextField(20);
                    jt_age.setText(tea.getAge());
                    jp2 =new JPanel();
                    jp2.add(jl_age);
                    jp2.add(jt_age);
                    jl_sex = new JLabel("性别");
                    jt_sex = new JTextField(20);
                    jt_sex.setText(tea.getSex());
                    jp3 =new JPanel();
                    jp3.add(jl_sex);
                    jp3.add(jt_sex);
                    if( tea.getTeaching_course() == null ){ 
                        jl_course = new JLabel("教授课程      "+"无");
                        jl_course.setForeground(Color.red);
                        jl_course.setFont(new Font("宋体",Font.ITALIC,16));                                                                   
                    }else if(tea.getTeaching_course().equals("无")){
                        jl_course = new JLabel("教授课程      "+"无");
                        jl_course.setForeground(Color.red);
                        jl_course.setFont(new Font("宋体",Font.ITALIC,16));   
                    } else {
                        jl_course = new JLabel("教授课程      "+tea.getTeaching_course().getCourseName());  
                    }           
                    jp_course = new JPanel();
                    jp_course.add(jl_course);
    
                    jl4 = new JLabel("修改成功");
                    jp4 = new JPanel();
                    jb = new JButton("修改信息");
                    jp_jb = new JPanel();
                    jp_jb.add(jb);
    
    
                    jp_center.add(jp1);
                    jp_center.add(jp2);
                    jp_center.add(jp3);         
                    jp_center.add(jp_course);
                    jp_center.add(jp_jb);
                    jp_center.add(jp4);
                    jf.setVisible(true);
    
                    jb.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {    
                            System.out.println(tea.toString());
                            tea.setName(jt_name.getText());
                            tea.setAge(jt_age.getText());
                            tea.setSex(jt_sex.getText());
                            if(tea.getTeaching_course() == null){
                                tea.setTeaching_course(new Course());
                            }else{
                                tea.setTeaching_course(tea.getTeaching_course());
                            }                       
                            Teacher newtea = tea;
                            DB.arrTea.clear();
                            DB.arrTea = IOStreamTeacher.readFromFile();
                            DB.arrTea.set(Login.searchTeacher(),newtea);
                            IOStreamTeacher.writeToFile();  
                            jp4.add(jl4);
                            jf.setVisible(true);
    
                        }                                       
                    });
                }
            });
            //修改密码
            jmb1revisePassword.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    jp_center.removeAll();
                    jp_center.setLayout(new GridLayout(6,2));
                    jf.add(jp_center, BorderLayout.CENTER);
                    jl_old_password = new JLabel("原密码");
                    jp_old_password = new JPasswordField(20);
                    jl_new_password1 = new JLabel("新密码");
                    jpassword1 = new JPasswordField(20);
                    jl_new_password2 = new JLabel("再次输入新密码");
                    jpassword2 = new JPasswordField(20);
                    jb_revise_password = new JButton("保存");
                    jl_inpassword_err = new JLabel("密码输入错误,请重新输入");
                    jl_inpassword_err.setForeground(Color.red);
                    jl_inpassword_err.setFont(new Font("宋体",Font.ITALIC,16));
                    JPanel jp1 = new JPanel();
                    JPanel jp2 = new JPanel();
                    JPanel jp3 = new JPanel();
                    final JPanel jp4 = new JPanel();
                    final JPanel jp5 = new JPanel();
                    JPanel jp_jb = new JPanel();
                    jp1.add(jl_old_password);
                    jp1.add(jp_old_password);
                    jp_center.add(jp1);
                    jp2.add(jl_new_password1);
                    jp2.add(jpassword1);
                    jp_center.add(jp2);
                    jp3.add(jl_new_password2);
                    jp3.add(jpassword2);
                    jp_center.add(jp3);
                    jp_center.add(jp4);
                    jp_jb.add(jb_revise_password);
                    jp_center.add(jp_jb);
                    jp_center.add(jp5);
                    jf.setVisible(true);
    
    
                    jb_revise_password.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            if (String.valueOf(jp_old_password.getPassword()).equals(tea.getPassword())
                                    && (!(String.valueOf(jpassword2.getPassword())).equals(""))
                                    && ((String.valueOf(jpassword1.getPassword())).equals(String.valueOf(jpassword2.getPassword())))) {
                                tea.setPassword(String.valueOf(jpassword2.getPassword()));
                                Teacher newstu = tea;
                                DB.arrTea.clear();
                                DB.arrTea = IOStreamTeacher.readFromFile();
                                DB.arrTea.set(Login.searchTeacher(), newstu);
                                IOStreamTeacher.writeToFile();
                                jp5.removeAll();
                                jp5.add(new JLabel("修改密码成功"));
                                jf.setVisible(true);
                            } else {
                                jp4.removeAll();
                                jp4.add(jl_inpassword_err);
                                jf.setVisible(true);
                            }
                        }
                    });     
                }
            });
            //查看所有学生这门课成绩
            jmb2find.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("查看所有学生成绩");
                    TeacherLogin.Excel();
                    model = (DefaultTableModel) table.getModel();
                    model.setColumnIdentifiers(new Object[] { "学生学号","学生姓名","《"+tea.getTeaching_course().getCourseName()+"》  成绩"});
                   CourseManage.allStudentOneCourse_mark(tea);
                   jf.setVisible(true);
                }
            });
            //老师给学生打分
            jmb2revise.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("修改成绩");
                    if (tea.getTeaching_course().courseName == null
                            || tea.getTeaching_course().courseName.equals("null")) {
                        JOptionPane.showMessageDialog(null, "请先让教务人员为您分配科目", "",
                                JOptionPane.WARNING_MESSAGE);
                    } else {
                    TeacherLogin.Excel();
                    model = (DefaultTableModel) table.getModel();
                    model.setColumnIdentifiers(new Object[] { "学生学号","学生姓名","《"+tea.getTeaching_course().getCourseName()+"》  成绩"});
                    CourseManage.allStudentOneCourse_mark(tea);            
                    jb_revise = new JButton("修改成绩");
                    jp_south.add(jb_revise);
                    jf.add(jp_south,BorderLayout.SOUTH);
                    jf.setVisible(true);
    
                    jb_revise.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             CourseManage.teacherReviseCourse_mark(tea);                        
                        }
                    });             
                }
                }
            });
        }
        //表格
        public static void Excel(){
            jp_center.removeAll();
            jp_south.removeAll();
            jp_center.setLayout(new GridLayout());
            scrollPane = new JScrollPane();             
            jp_center.add(scrollPane);
            jf.add(jp_center,BorderLayout.CENTER);
    
            table = new JTable();
            // 将表的选择模式设置为只允许单个选择、单个连续间隔选择或多间隔选择。 
            table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            table.setShowGrid(true);
            table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
            table.setRowHeight(30);
            JTableHeader header = table.getTableHeader(); // 获取 JTable 的头的对象
            header.setFont(new Font("微软雅黑", Font.PLAIN, 16));
            header.setPreferredSize(new Dimension(header.getWidth(), 35)); // 设置此组件的首选大小
            scrollPane.setViewportView(table);
        }
    
    }
    
    

    看图,显示信息,因为教务人员没有给老师分配教授的科目,所以科目一栏为无。

    这里写图片描述

    查看学生成绩,这里只有注册的学生1,点击修改成绩,显示错误,因为教务人员没有给老师分配教授的科目。

    这里写图片描述

    3.教务人员界面

    有菜单选项自己信息,学生(查看,修改,删除),老师(查看,修改,删除)。

    package com.file;
    
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.Iterator;
    
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextField;
    import javax.swing.ListSelectionModel;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.JTableHeader;
    
    public class ManageLogin {
    
        static JFrame jf;
        JLabel jl_name, jl11, jl21,jl31, jl4,jl_password;
        JPasswordField jpassword;
        JTextField jt_name;
        JPanel jp1, jp2, jp4, jp_jb, jp_img,jp_scroll;
        static JPanel jp_center,jp_south;
        JButton jb,jb_revise_teacher;
        static JTable table;
        static JScrollPane scrollPane;
        static DefaultTableModel model;
         JMenuBar jmb;
         JMenuItem jmb1findStudentMessage,jmb2findTeacherMessage,jmb1reviseStudentMessage,jmb2revise,jmb0message,jmb1deleteStudent,jmb2deleteTeacher;
    
        public ManageLogin(final Manage man) {
    
            jf = new JFrame("欢迎 " + man.getId() + " 教务管理员,你好!");
            jf.setSize(1000, 700);
            jf.setLocation(800, 100);
            jf.setLayout(new BorderLayout(0,0));
            Icon img = new ImageIcon("tu2.jpg");
            jf.add(new JLabel(img),BorderLayout.NORTH);
    
            jmb = new JMenuBar();
            jf.setJMenuBar(jmb);    
            JMenu jmb0 = new JMenu("我的信息");
            jmb.add(jmb0);
            jmb0message = new JMenuItem("查看和修改");
            jmb0.add(jmb0message);      
            JMenu jmb1 = new JMenu("学生管理");
            jmb.add(jmb1);
            jmb1findStudentMessage = new JMenuItem("查看学生信息");
            jmb1.add(jmb1findStudentMessage);   
            jmb1reviseStudentMessage = new JMenuItem("修改学生信息");
            jmb1.add(jmb1reviseStudentMessage);
            jmb1deleteStudent = new JMenuItem("删除学生信息");
            jmb1.add(jmb1deleteStudent);
    
            JMenu jmb2 = new JMenu("老师管理");
            jmb.add(jmb2);
            jmb2findTeacherMessage = new JMenuItem("查看老师信息");
            jmb2.add(jmb2findTeacherMessage);
            jmb2revise = new JMenuItem("修改老师信息");
            jmb2.add(jmb2revise);
            jmb2deleteTeacher = new JMenuItem("删除老师信息");
            jmb2.add(jmb2deleteTeacher);
    
            jp_center = new JPanel();//中心的面板
            jp_south = new JPanel();//下方的面板
            jf.setVisible(true);
            //查看和修改自己信息
            jmb0message.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    jp_center.removeAll();
                    jp_center.setLayout(new GridLayout(7,2));
                    jf.add(jp_center,BorderLayout.CENTER);
    
                    jl_name = new JLabel("姓名");
                    jt_name = new JTextField(20);
                    jt_name.setText(man.getName());
                    jp1 = new JPanel();
                    jp1.add(jl_name);
                    jp1.add(jt_name);
    
                    jl_password = new JLabel("密码");
                    jpassword = new JPasswordField(20);
                    jpassword.setText(man.getPassword());
                    jp2 = new JPanel();
                    jp2.add(jl_password);
                    jp2.add(jpassword);
    
                    jl4 = new JLabel("修改成功");
                    jp4 = new JPanel();
                    jb = new JButton("修改信息");
                    jp_jb = new JPanel();
                    jp_jb.add(jb);
    
                    jp_center.add(jp1);
                    jp_center.add(jp2);
                    jp_center.add(jp_jb);
                    jp_center.add(jp4);
                    jf.setVisible(true);
    
                    jb.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
    
                            man.setName(jt_name.getText());
                            man.setPassword(String.valueOf(jpassword.getPassword()));
                            Manage newman = man;
                            DB.arrMan.clear();
                            DB.arrMan = IOStreamManage.readFromFile();
                            DB.arrMan.set(Login.searchManage(), newman);
                            IOStreamManage.writeToFile();
                            jp4.add(jl4);
                            jf.setVisible(true);
                        }
                    });
                }
            });
            //查看学生信息
            jmb1findStudentMessage.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("查看所有学生信息");
                    ManageLogin.Excel();
                    model = (DefaultTableModel) table.getModel();
                    model.setColumnIdentifiers(new Object[] { "用户名", "姓名", "年龄","性别" });
                    CourseManage.findAllStudentMessage();
                    jp_center.add(scrollPane);
                    jf.setVisible(true);
    
                }
            });
            //修改学生信息
            jmb1reviseStudentMessage.addActionListener(new ActionListener() {           
                public void actionPerformed(ActionEvent e) {
                    CourseManage.jmb1reviseStudentMessage();                
                }
            });
            //删除学生
            jmb1deleteStudent.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    CourseManage.deleteStudent();           
                }
            });
    
    
            //查看老师信息
            jmb2findTeacherMessage.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("查看所有老师信息");
                    ManageLogin.Excel();
                    model = (DefaultTableModel) table.getModel();
                    model.setColumnIdentifiers(new Object[] { "用户名", "姓名", "年龄", "性别", "课程编号" ,"教授课程" });
                    CourseManage.findAllTeacherMessage();
                    jp_center.add(scrollPane);
                    jf.setVisible(true);
    
                }
            });
            //修改老师信息
            jmb2revise.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    ManageLogin.Excel();
                    model = (DefaultTableModel) table.getModel();
                    model.setColumnIdentifiers(new Object[] { "用户名", "姓名", "年龄","性别", "课程编号", "教授课程" });
                    CourseManage.findAllTeacherMessage();           
                    jb_revise_teacher = new JButton("修改");
                    jp_south.add(jb_revise_teacher);
                    jf.add(jp_south,BorderLayout.SOUTH);
                    jf.setVisible(true);
    
                    jb_revise_teacher.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                        CourseManage.teacherReviseJudge();                      
                        }
                    });             
                }
            });
            //删除老师
            jmb2deleteTeacher.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    CourseManage.deleteTeacher();           
                }
            });         
        }
    
        //表格模型
        public static void Excel(){
            jp_center.removeAll();
            jp_south.removeAll();
            jp_center.setLayout(new GridLayout());
            scrollPane = new JScrollPane();
            jp_center.add(scrollPane);
            jf.add(jp_center, BorderLayout.CENTER);
            jf.setVisible(true);
            table = new JTable();
            table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
            table.setRowHeight(30);
            JTableHeader header = table.getTableHeader(); // 获取 JTable 的头的对象
            header.setFont(new Font("微软雅黑", Font.PLAIN, 16));
            header.setPreferredSize(new Dimension(header.getWidth(), 35)); // 设置此组件的首选大小
            scrollPane.setViewportView(table);
        }
    
    }
    

    查看学生

    这里写图片描述

    修改学生信息

    这里写图片描述

    删除学生

    这里写图片描述

    查看老师,此时老师没有安排课程

    这里写图片描述

    修改老师信息,顺便安排课程,这里安排老师1上《高等数学》,这里要是想要修改别的都可以加

    这里写图片描述

    修改之后,老师科目已经安排,老师1教高等数学

    这里写图片描述

    这时登录老师1的界面给学生修改成绩,科目栏已经变为《高等数学》。

    这里写图片描述

    登录学生1端口查看成绩

    这里写图片描述

    工具处理类

    package com.file;
    
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.Iterator;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    public class CourseManage {
        static JFrame jf ;
        static JPanel jp ;
        static JLabel jl ;
        static JButton jb ;
        static JTextField jt_name,jt_id,jt_pass; 
        //老师查找所有学生单科成绩
        public static void allStudentOneCourse_mark(Teacher tea) {
            ArrayList<Student> arr = IOStreamStudent.readFromFile();
            Iterator<Student> itarr = arr.iterator();
            String course_mark = null;// 查找的课程
            while (itarr.hasNext()) {       
                Student stu = itarr.next();      //一个循环内不能存在2个.next()方法
                String id = stu.getId();
                String name = stu.getName();
                for(int i = 0;i<stu.arr_course.size();i++){
                    if (tea.getTeaching_course().getCourseName()
                            .equals(stu.arr_course.get(i).getCourseName())) {
                        course_mark = stu.arr_course.get(i).getCourseMark();
                        break;
                    }
                }       
                TeacherLogin.model.addRow(new Object[] { id, name, course_mark });
                TeacherLogin.table.setModel(TeacherLogin.model);
            }
        }
    
        //老师修改学生单科成绩
        public static void teacherReviseCourse_mark(Teacher tea) {
            if (tea.getTeaching_course().courseName == null
                    || tea.getTeaching_course().courseName.equals("null")) {
                JOptionPane.showMessageDialog(null, "请先让教务人员为您分配科目", "",
                        JOptionPane.WARNING_MESSAGE);
            } else {
                int index = 0;
                String student_course_mark = null;
                Course newcourse = null;
                index = TeacherLogin.table.getSelectedRow();
                if (index == -1) {
                    JOptionPane.showMessageDialog(null, "请选择要修改成绩的学生", "",
                            JOptionPane.WARNING_MESSAGE);
                } else {
                    String id = (String) TeacherLogin.table.getValueAt(index, 0);
                    DB.arrStu.clear();
                    DB.arrStu = IOStreamStudent.readFromFile();
                    student_course_mark = JOptionPane.showInputDialog("成绩=", 0);
                    for (int i = 0; i < DB.arrStu.size(); i++) {
                        if (id.equals(DB.arrStu.get(i).getId())) {
                            if (DB.arrStu.get(i).arr_course.size() == 0) {       //成绩集合为空,添加第一个数据
                                newcourse = new Course(tea.getTeaching_course()
                                        .getCourseId(), tea.getTeaching_course()
                                        .getCourseName(), student_course_mark);
                                DB.arrStu.get(i).arr_course.add(newcourse);
                            } else {
                                for (int j = 0; j < DB.arrStu.get(i).arr_course.size(); j++) {          //这门课程已经创建,进行修改
                                    if (DB.arrStu.get(i).arr_course.get(j).getCourseName()
                                            .equals(tea.getTeaching_course().getCourseName())) {
                                        newcourse = new Course(
                                                tea.getTeaching_course()
                                                        .getCourseId(), tea
                                                        .getTeaching_course()
                                                        .getCourseName(),
                                                student_course_mark);
                                        DB.arrStu.get(i).arr_course.set(j,newcourse);
                                        break;
                                    } else {        //这门课程没有创建时,进行添加
                                        newcourse = new Course(tea.getTeaching_course()
                                                .getCourseId(), tea.getTeaching_course()
                                                .getCourseName(), student_course_mark);
                                        DB.arrStu.get(i).arr_course.add(newcourse);
                                    }
                                }
                            }
                            IOStreamStudent.writeToFile();
    
                            TeacherLogin.model.removeRow(TeacherLogin.table.getSelectedRow());
                            TeacherLogin.model.insertRow(index,new Object[] { DB.arrStu.get(i).getId(),DB.arrStu.get(i).getName(),student_course_mark });
                            TeacherLogin.table.setModel(TeacherLogin.model);
                            break;
                        }
                    }
                }
            }
        }
    
    
        //一个学生的所有成绩
        public static void findOneStudentAllCourseMark(Student stu) {
            ArrayList<Student> arrStu = IOStreamStudent.readFromFile();
            Iterator<Student> it = arrStu.iterator();   
            String teacher_name  = null;
            if(stu.arr_course == null) {
                JOptionPane.showMessageDialog(null, "无成绩,请等待老师给定", "",JOptionPane.WARNING_MESSAGE);
            } else {
                ArrayList<Teacher> arrTea = IOStreamTeacher.readFromFile();
                while(it.hasNext()) {
                Student newstu = it.next();
                if(newstu.getId().equals(stu.getId())) {
                    for(int i = 0;i<newstu.arr_course.size();i++) { 
                        String course_id = newstu.arr_course.get(i).getCourseId();
                        String course_name = newstu.arr_course.get(i).getCourseName();
                        String course_mark = newstu.arr_course.get(i).getCourseMark(); 
                        for(int j = 0;j<arrTea.size();j++) {
                            if(course_name.equals(arrTea.get(j).getTeaching_course().getCourseName())) {
                                teacher_name = arrTea.get(j).getName();
                                StudentLogin.model.addRow(new Object[] {course_id,course_name,course_mark,teacher_name});
                                StudentLogin.table.setModel(StudentLogin.model); 
                            }
                        }                   
                    }               
                    break;
                }           
                }       
            }
    
        } 
    
        //查看所有学生信息
        public static void findAllStudentMessage(){
            ArrayList<Student> arr = IOStreamStudent.readFromFile();
            Iterator<Student> it = arr.iterator();//next()方法不能在循环内使用2次
            while(it.hasNext()){    
    
                Student stu = it.next();
                String id = stu.getId();
                String name = stu.getName();
                String sex = stu.getSex();
                String age = stu.getAge();  
                ManageLogin.model.addRow(new Object[] {id,name,sex,age});
                ManageLogin.table.setModel(ManageLogin.model); 
            }   
    
        }
        //修改学生信息
        public static void jmb1reviseStudentMessage(){
            jf = new JFrame("修改学生信息");
            jf.setLocation(1000, 200);
            jf.setSize(400, 300);
            jf.setLayout(new GridLayout(4, 1));
            jp = new JPanel();
            jl = new JLabel("输入要修改的用户名:");
            jt_id = new JTextField(15);
            jp.add(jl);
            jp.add(jt_id);
            jf.add(jp);
            jl = new JLabel("用户密码:");
            jt_pass = new JTextField(15);
            jp = new JPanel();
            jp.add(jl);
            jp.add(jt_pass);
            jf.add(jp);
            jb = new JButton("确定修改");
            jp = new JPanel();
            jp.add(jb);
            jf.add(jp);
            jf.setVisible(true);
            jb.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    jf.dispose();   
                    DB.arrStu.clear();
                    DB.arrStu = IOStreamStudent.readFromFile();
                    for(int i = 0;i<DB.arrStu.size();i++){
                        if(DB.arrStu.get(i).getId().equals(jt_id.getText())){
                            DB.arrStu.get(i).setId(jt_id.getText());
                            DB.arrStu.get(i).setPassword(jt_pass.getText());                        
                            IOStreamStudent.writeToFile();                  
                        }
                    }
                }
            });
        } 
        //删除学生账户
        public static void deleteStudent(){
            String id = JOptionPane.showInputDialog("要删除的用户名", 0);
            DB.arrStu.clear();
            DB.arrStu = IOStreamStudent.readFromFile();
            for(int i = 0;i<DB.arrStu.size();i++){
                if(DB.arrStu.get(i).getId().equals(id)){
                    DB.arrStu.remove(i);                
                    IOStreamStudent.writeToFile();                  
                }
            }
        }
        //删除老师账户
            public static void deleteTeacher(){
                String id = JOptionPane.showInputDialog("要删除的用户名", 0);
                DB.arrTea.clear();
                DB.arrTea = IOStreamTeacher.readFromFile();
                for(int i = 0;i<DB.arrTea.size();i++){
                    if(DB.arrTea.get(i).getId().equals(id)){
                        DB.arrTea.remove(i);                
                        IOStreamTeacher.writeToFile();                  
                    }
                }
            }
        //查看所有老师信息
        @SuppressWarnings("unused")
        public static void findAllTeacherMessage() {
            if (IOStreamTeacher.file.length() == 0) {
                ManageLogin.model.addRow(new Object[] { "无" });
                ManageLogin.table.setModel(ManageLogin.model);
            } else {
                ArrayList<Teacher> arr = IOStreamTeacher.readFromFile();
                Iterator<Teacher> it = arr.iterator();
    
                while (it.hasNext()) {
    
                    Teacher tea = it.next();
                    String id = tea.getId();
                    String name = tea.getName();
                    String sex = tea.getSex();
                    String age = tea.getAge();
                    if (tea.getTeaching_course() == null) {
                        ManageLogin.model.addRow(new Object[] { id, name, sex, age,
                                "无","无" });
                        ManageLogin.table.setModel(ManageLogin.model);
                    } else {
                        String teaching_course_id = tea.getTeaching_course()
                                .getCourseId();
                        String teaching_course_name = tea.getTeaching_course().getCourseName();
                        ManageLogin.model.addRow(new Object[] { id, name, sex, age,
                                teaching_course_id, teaching_course_name });
                        ManageLogin.table.setModel(ManageLogin.model);
                    }
                }
            }
    
        }
    
        //教务修改老师信息
        //第一步教务修改老师信息判断条件
        public static void teacherReviseJudge() {
            int index = 0;
            index = ManageLogin.table.getSelectedRow();
            if (index == -1) {
                JOptionPane.showMessageDialog(null, "请选择要修改的老师", "",
                        JOptionPane.WARNING_MESSAGE);
            } else {
                CourseManage.teacherReviseFrame(index);
            }
        }
        //第二步教务修改老师信息面板
        public static void teacherReviseFrame(final int index) {
            jf = new JFrame("修改老师信息");
            jf.setLocation(1000, 200);
            jf.setSize(300, 400);
            jf.setLayout(new GridLayout(4, 1));
            JPanel jp1 = new JPanel();
            JPanel jp2 = new JPanel();
            JPanel jp3 = new JPanel();
            JPanel jp4 = new JPanel();
    
            jl = new JLabel("修改用户密码:");
            jt_pass = new JTextField(15);
            jp1.add(jl);
            jp1.add(jt_pass);
            jf.add(jp1);
            jl = new JLabel("安排课程编号");
            jt_id = new JTextField(15);
            jp2.add(jl);
            jp2.add(jt_id);
            jf.add(jp2);
            jl = new JLabel("课程名称");
            jt_name = new JTextField(15);
            jp3.add(jl);
            jp3.add(jt_name);
            jf.add(jp3);
            jb = new JButton("确定修改");
            jp4.add(jb);
            jf.add(jp4);
            jf.setVisible(true);
            jb.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    jf.dispose();
                    CourseManage.teacherRevise(index);
                }
            });
        }
        //第三步教务修改老师信息
        public static void teacherRevise(int index) {
            String teacher_course_id = null;
            String teacher_course_name = null;
    
            String id = (String) ManageLogin.table.getValueAt(index, 0);
            DB.arrTea.clear();
            DB.arrTea = IOStreamTeacher.readFromFile();
            teacher_course_id = jt_id.getText();
            teacher_course_name = jt_name.getText();
            for (int i = 0; i < DB.arrTea.size(); i++) {
                if (id.equals(DB.arrTea.get(i).getId())) {
                    if(!(jt_pass.getText().equals(""))){
                        DB.arrTea.get(i).setPassword(jt_pass.getText());
                    }           
                    DB.arrTea.get(i).getTeaching_course()
                            .setCourseName(teacher_course_name);
                    DB.arrTea.get(i).getTeaching_course()
                            .setCourseId(teacher_course_id);
                    IOStreamTeacher.writeToFile();
                    ManageLogin.model.removeRow(index);
                    ManageLogin.model.insertRow(index, new Object[] {
                            DB.arrTea.get(i).getId(), DB.arrTea.get(i).getName(),
                            DB.arrTea.get(i).getAge(), DB.arrTea.get(i).getSex(),
                            teacher_course_id, teacher_course_name });
                    ManageLogin.table.setModel(ManageLogin.model);
                    break;
                }
            }
        }
    
    
    }

    主类

    package com.file;
    
    /*2017年12月
     * 《教学管理系统》有学生,教师,教务3个角色。
     * 只有一个系统管理员,用来添加学生,教师和教务人员帐号,帐号id为111,密码为111,请妥善保存。
     * 
     */
    public class MainText {
        public static void main(String[] args) {
            new Login();
        }
    }
    
    展开全文
  • java 学生成绩管理系统

    千次阅读 多人点赞 2017-05-30 23:29:01
    java实现学生成绩管理系统,可实现学生成绩的增加、删除、修改、查询功能

    background.java 登录页面的背景面板

    package stu;

    import java.awt.*;

    import javax.swing.*;

    public class background extends JPanel{

    Image im;

    public background(Image im)

    {

       this.im=im;

       this.setOpaque(true);

    }

    //Draw the back ground.

    public void paintComponent(Graphics g)

    {

       super.paintComponents(g);

       g.drawImage(im,0,0,this.getWidth(),this.getHeight(),this);

        

    }

    }

    home.java登录页面

    package stu;

    //package stu;//登录页面

    import java.awt.*;

    import javax.swing.*;

    import java.awt.event.*;

    public class home extends JFrame implements ActionListener{

    Container ct=this.getContentPane();

        JTextField f1=new JTextField(10);

    JPasswordField f2=new JPasswordField(10);

    JButton button1=new JButton("登录");

    JButton button2=new JButton("重置");

    background bgp=new background((new ImageIcon("picture.png")).getImage());//创建背景面板。

    JPanel p=new JPanel();

    JPanel p1=new JPanel();

    JPanel p2=new JPanel();

    JPanel p3=new JPanel();

    JPanel p4=new JPanel();

    JLabel label=new JLabel("用户名或密码错误!");

    home(){

    init();

    setVisible(true);

    setBounds(300,200,550,430);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    void init(){

    setTitle("学生成绩管理系统");

            p.setLayout(new BorderLayout());

            p.setBounds(100,100,100,100);

    p1.setLayout(new GridLayout(2,1));

    p.setOpaque(false);

            bgp.setBounds(0,0,550,430);

            p3.add(new JLabel("用户名:"));

    p3.add(f1);

    p4.add(new JLabel("    密码:"));

    p4.add(f2);

    p1.add(p3);

    p1.add(p4);

    p2.add(button1);

    p2.add(button2);

    p.add(p1,BorderLayout.CENTER);

    p.add(p2, BorderLayout.SOUTH);

    bgp.add(p);

    bgp.add(label);

    label.setVisible(false);

    ct.add(bgp);

    button1.addActionListener(this);

    button2.addActionListener(this);

    }

    public void actionPerformed(ActionEvent e){

    if(e.getSource()==button1){

    if(f1.getText().equals(f2.getText())){

    this.setVisible(false);

    new index();

     

    }

    else{

        label.setVisible(true);

    }

    }

    if(e.getSource()==button2){

    f1.setText(null);

    f2.setText(null);

    }

    }

    }

     

    connect.java   java连接数据库

    package stu;

    //package stu;

    import java.sql.*;

    import java.sql.Connection;

    import java.sql.DriverManager;

    import java.sql.SQLException;

    public class connect {

    static String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";   

      static String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=javastu";   

      static String userName = "sa";  //默认用户名

      static String userPwd = "123456";  //密码

      static Connection dbConn;

      public void setcon(Connection con2){

      dbConn=con2;

      }

      public static Connection connection() {

    try {

       Class.forName(driverName);

       dbConn = DriverManager.getConnection(dbURL, userName, userPwd);

       System.out.println("Connection Successful!");

      } catch (Exception e) {

       e.printStackTrace();

      }

     

    return  dbConn;

    }

    }

     

     

     

    index.java    学生管理系统首页

    package stu;

    //package stu;

    import java.awt.*;

    import javax.swing.*;

    import java.awt.event.*;

    import java.sql.Connection;

    import java.sql.PreparedStatement;

    import java.sql.ResultSet;

    import java.sql.SQLException;

    import java.sql.Statement;

    public class xingming extends JPanel implements ActionListener{

    JLabel xmlabel1=new JLabel("请输入要查询学生的姓名:");

    JTextField xmf1=new JTextField(10);

    JButton xmbutton1=new JButton("确定");

    JLabel xmlabel2=new JLabel("学号:");

    JTextField xmf2=new JTextField(10);

    JLabel xmlabel3=new JLabel("姓名:");

    JTextField xmf3=new JTextField(10);

    JLabel xmlabel4=new JLabel("性别:");

    JTextField xmf4=new JTextField(10);

    JLabel xmlabel5=new JLabel("jsp分数:");

    JTextField xmf5=new JTextField(10);

    JLabel xmlabel6=new JLabel("java分数:");

    JTextField xmf6=new JTextField(10);

    JLabel xmlabel7=new JLabel("c分数:");

    JTextField xmf7=new JTextField(10);

    JLabel xmlabel8=new JLabel("平均分:");

    JTextField xmf8=new JTextField(10);

    JButton xmbutton2=new JButton("删除");

    JLabel xmlabel10=new JLabel("若要修改该学生信息,请将修改后的信息填入文本框!");

    JButton xmbutton3=new JButton("确认修改");

    JPanel xingming=new JPanel();

    xingming(){

    init();

    setBounds(100,100,600,650);

    setVisible(true);

    }

    void init(){

    setLayout(null);

        xmlabel1.setBounds(50,10,180,20);

        xmf1.setBounds(230,10,150,20);

        xmbutton1.setBounds(500,10,60,30);

        xmlabel2.setBounds(50,60,50,20);

        xmf2.setBounds(120,60,120,20);

        xmlabel3.setBounds(50,90,50,20);

        xmf3.setBounds(120,90,120,20);

        xmlabel4.setBounds(50,120,50,20);

        xmf4.setBounds(120,120,120,20);

        xmlabel5.setBounds(50,150,80,20);

        xmf5.setBounds(120,150,120,20);

        xmlabel6.setBounds(300,60,80,20);

        xmf6.setBounds(400,60,120,20);

        xmlabel7.setBounds(300,90,80,20);

        xmf7.setBounds(400,90,120,20);

        xmlabel8.setBounds(300,120,50,20);

        xmf8.setBounds(400,120,120,20);

        xmbutton2.setBounds(500,150,60,30);

        xmlabel10.setBounds(120,250,320,30);

        xmbutton3.setBounds(480,250,90,30);

        add(xmlabel1);

        add(xmf1);

        add(xmbutton1);

        add(xmlabel2);

        add(xmf2);

        add(xmlabel3);

        add(xmf3);

        add(xmlabel4);

        add(xmf4);

        add(xmlabel5);

        add(xmf5);

        add(xmlabel6);

        add(xmf6);

        add(xmlabel7);

        add(xmf7);

        add(xmlabel8);

        add(xmf8);

        add(xmbutton2);

        add(xmlabel10);

        add(xmbutton3);

        xmbutton1.addActionListener(this);

        xmbutton2.addActionListener(this);

        xmbutton3.addActionListener(this);

     

    }

    public void actionPerformed(ActionEvent e){

    //根据姓名查询某一学生信息ok

    if(e.getSource()==xmbutton1){//查询

    try {

    Connection con = connect.connection();

    String name = xmf1.getText();

    String sql = "select * from student where name='"+name+"'";

    Statement s = con.createStatement();

    ResultSet rs = s.executeQuery(sql);

    if(rs.next()){

    xmf2.setText(rs.getString(1));

    xmf3.setText(name);

    xmf4.setText(rs.getString(3));

    xmf5.setText(rs.getString(4));

    xmf6.setText(rs.getString(5));

    xmf7.setText(rs.getString(6));

    xmf8.setText(rs.getString(7));

    }

    } catch (SQLException e1) {

     

    e1.printStackTrace();

    }

     

    }

    if(e.getSource()==xmbutton2){//删除数据库中该姓名对应的行

    try {

    Connection con = connect.connection();

    String name = xmf1.getText();

    PreparedStatement ps = con.prepareStatement("delete from student where name='"+ name+"'");

    ps.executeUpdate();

    } catch (SQLException e1) {

     

    e1.printStackTrace();

    }

    xmf1.setText("");

    xmf2.setText("");

    xmf3.setText("");

    xmf4.setText("");

    xmf5.setText("");

    xmf6.setText("");

    xmf7.setText("");

    xmf8.setText("");

    }

    if(e.getSource()==xmbutton3){//修改

    String name = xmf1.getText();

    try {

    Connection con = connect.connection();

    PreparedStatement ps = con.prepareStatement("update student set no=?,name=?,sex=?,jsp=?,java=?,c=?,ave=? where name='"+ name+"'");

        ps.setString(1,xmf2.getText());

    ps.setString(2,xmf3.getText());

    ps.setString(3,xmf4.getText());

    ps.setString(4,xmf5.getText());

    ps.setString(5,xmf6.getText());

    ps.setString(6,xmf7.getText());

    ps.setString(7,xmf8.getText());

    ps.executeUpdate();

    } catch (NumberFormatException e1) {

    e1.printStackTrace();

    } catch (SQLException e1) {

                e1.printStackTrace();

    }

    }

    }

    }

     

     

     luru.java    录入页面

    package stu;

    //package stu;

    import java.awt.*;

    import javax.swing.*;

    import java.awt.event.*;

    import java.sql.Connection;

    import java.sql.PreparedStatement;

    import java.sql.ResultSet;

    import java.sql.SQLException;

    import java.sql.Statement;

    public class luru extends JPanel implements ActionListener,MouseListener,MouseMotionListener{

    int rows=50;

    Object [][]a0=new Object[rows][7];

    Object []name={ "学号","姓名","性别","jsp","java","c","平均成绩"};

    JTable table1=new JTable(a0,name);

    JButton lurubutton1=new JButton("计算");

    JButton lurubutton2=new JButton("保存");

    JLabel lulabe1=new JLabel();

    JLabel lulabe2=new JLabel();

        JPanel lurup1=new JPanel();

        int flag=0;

        double a[]=new double[50] ;

        double b[]=new double[50] ;

    luru(){

    init();

    setBounds(100,100,600,650);

    setVisible(true);

    }

    void init(){

    setLayout(new BorderLayout());

    lurup1.setLayout(new FlowLayout());

    lurubutton1.addActionListener(this);

    lurubutton2.addActionListener(this);

    add(new JScrollPane(table1),BorderLayout.CENTER);

    lurup1.add(lulabe1);

    lurup1.add(lulabe2);

          lurup1.add(lurubutton1);

          lurup1.add(lurubutton2);

            add(lurup1,BorderLayout.SOUTH);

            table1.addMouseListener(this);

            table1.addMouseMotionListener(this);

    }

     int add(JTable table){//确定table中编辑的行数

     int num=0;

     for(int i=0;i<50;i++){

     String m=(String)table.getValueAt(i, 0);

     if(m!=null){

     num++;

     }

     }

     return num;

     }

     

    public void actionPerformed(ActionEvent e){

    //计算

    if(e.getSource()==lurubutton1){

    for(int i3=0;i3<add(table1);i3++){

    String a1=(String)table1.getValueAt(i3,3);

    System.out.println(a1);

    int m1=Integer.parseInt(a1);

    String a2=(String)table1.getValueAt(i3,4);

    int m2=Integer.parseInt(a2);

    String a3=(String)table1.getValueAt(i3,5);

    int m3=Integer.parseInt(a3);

    String aValue=""+((m1+m2+m3)*1.0/3);

    table1.setValueAt(aValue,i3,6);

        }

    }

    //录入

    if(e.getSource()==lurubutton2){//向数据库中录入学生信息

    flag++;

    if((flag-1)==0){

    try {

    Connection con = connect.connection();

    PreparedStatement ps = con.prepareStatement("insert into student values(?,?,?,?,?,?,?)");

    for(int i=0;i<add(table1);i++){

    ps.setString(1, (String)table1.getValueAt(i, 0));

    ps.setString(2, (String)table1.getValueAt(i, 1));

    ps.setString(3, (String)table1.getValueAt(i, 2));

    ps.setString(4, (String)table1.getValueAt(i, 3));

    ps.setString(5, (String)table1.getValueAt(i, 4));

    ps.setString(6, (String)table1.getValueAt(i, 5));

    ps.setString(7, (String)table1.getValueAt(i, 6));

    ps.executeUpdate();

    }

    } catch (NumberFormatException e1) {

    e1.printStackTrace();

    } catch (SQLException e1) {

    e1.printStackTrace();

    }

    }

    else{

    try {

    Connection con = connect.connection();

    String sql = "select no from student ";

    Statement s = con.createStatement();

    ResultSet rs = s.executeQuery(sql);

        while(rs.next()){

         PreparedStatement ps = con.prepareStatement("delete from student where no='"+ rs.getString(1)+"'");//删除数据库中该学号对应的行

    ps.executeUpdate();

    }

    } catch (SQLException e1) {

       e1.printStackTrace();

     }

    try {

    Connection con = connect.connection();

    PreparedStatement ps = con.prepareStatement("insert into student values(?,?,?,?,?,?,?,?)");

    for(int i=0;i<add(table1);i++){

    ps.setString(1, (String)table1.getValueAt(i, 0));

    ps.setString(2, (String)table1.getValueAt(i, 1));

    ps.setString(3, (String)table1.getValueAt(i, 2));

    ps.setString(4, (String)table1.getValueAt(i, 3));

    ps.setString(5, (String)table1.getValueAt(i, 4));

    ps.setString(6, (String)table1.getValueAt(i, 5));

    ps.setString(7, (String)table1.getValueAt(i, 6));

    ps.executeUpdate();

    }

    } catch (NumberFormatException e1) {

    e1.printStackTrace();

    } catch (SQLException e1) {

    e1.printStackTrace();

    }

    }

         

    }

    }

    public void mousePressed(MouseEvent e){//对学号和年龄进行处理

    for(int j=0;j<add(table1);j++){

    String fcf=(String)table1.getValueAt(j,0);

    if(fcf==null){}

    else{

    if(fcf.length()!=11)

    lulabe1.setText("学号格式输入有误,请输入的学号格式为11位!");

    else lulabe1.setText("");

    }

    }

     

    for(int j=1;j<=add(table1);j++){

    String fcf=(String)table1.getValueAt(j-1,3);

    if(fcf==null){}

    else{

    int m=Integer.parseInt(fcf);

    if(m<0||m>100)

    lulabe2.setText("成绩输入有误,请输入0~100之间的成绩!");

    else lulabe2.setText("");

    }

    }

    for(int j=1;j<=add(table1);j++){

    String fcf=(String)table1.getValueAt(j-1,4);

    if(fcf==null){}

    else{

    int m=Integer.parseInt(fcf);

    if(m<0||m>100)

    lulabe2.setText("成绩输入有误,请输入0~100之间的成绩!");

    else lulabe2.setText("");

    }

    }

    for(int j=1;j<=add(table1);j++){

    String fcf=(String)table1.getValueAt(j-1,5);

    if(fcf==null){}

    else{

    int m=Integer.parseInt(fcf);

    if(m<0||m>100)

    lulabe2.setText("成绩输入有误,请输入0~100之间的成绩!");

    else lulabe2.setText("");

    }

    }

       }

    public void mouseReleased(MouseEvent e) {}

    public void mouseEntered(MouseEvent e){}

    public void mouseExited(MouseEvent e) {}

    public void mouseClicked(MouseEvent e) {}

    public void mouseDragged(MouseEvent e){}

    public void mouseMoved(MouseEvent e)  {}

     

    }

     

    chakan.java   查看全部信息页面

    package stu;

    //package stu;

     

    import java.awt.*;

    import javax.swing.*;

    import java.awt.event.*;

    import java.sql.Connection;

    import java.sql.PreparedStatement;

    import java.sql.ResultSet;

    import java.sql.SQLException;

    import java.sql.Statement;

    public class chakan extends JPanel implements ActionListener{

    int row=50;

    Object [][]a1=new Object[row][7];

    Object []name1={ "学号","姓名","性别","jsp","java","c","平均成绩"};

    JPanel chakan1=new JPanel();

    JTable table2=new JTable(a1,name1);

    JButton ckbutton=new JButton("查看全部信息");

    chakan(){

    init();

    setBounds(100,100,600,650);

    setVisible(true);

    }

    void init(){

    //查看全部信息

        setLayout(new BorderLayout());

    chakan1.setLayout(new FlowLayout());

        add(new JScrollPane(table2),BorderLayout.CENTER);

            chakan1.add(ckbutton);

            add(chakan1,BorderLayout.NORTH);

            ckbutton.addActionListener(this);

     

    }

     int add(JTable table){//确定table1中编辑的行数

     int num=0;

     for(int i=0;i<50;i++){

     String m=(String)table.getValueAt(i, 0);

     if(m!=null){

     num++;

     }

     }

     return num;

     }

    public void actionPerformed(ActionEvent e){

    if(e.getSource()==ckbutton){

    try {

    Connection con = connect.connection();

    String sql = "select * from student ";//获取数据库中所有学号

    Statement s = con.createStatement();

    ResultSet rs = s.executeQuery(sql);

        for(int i=0;rs.next();i++){

    table2.setValueAt(rs.getString(1),i,0);

    table2.setValueAt(rs.getString(2),i,1);

    table2.setValueAt(rs.getString(3),i,2);

    table2.setValueAt(rs.getString(4),i,3);

    table2.setValueAt(rs.getString(5),i,4);

    table2.setValueAt(rs.getString(6),i,5);

    table2.setValueAt(rs.getString(7),i,6);

    }

    } catch (SQLException e1) {

     

    e1.printStackTrace();

    }

    try{

    Connection con = connect.connection();

    String sql = "select no from student";//删除table2中重复行

    Statement s = con.createStatement();

    ResultSet rs = s.executeQuery(sql);

    int count=0;

    while(rs.next()){

    count++;

    }

    for(int m=count;m<add(table2);m++){

       for(int n=0;n<7;n++){

         table2.setValueAt("",m,n);

       }

     }

    }

    catch (SQLException e1) {

     

    e1.printStackTrace();}

        }

     

    }

    }

     

     

     

    xingming.java   按姓名查询页面

    package stu;

    //package stu;

    import java.awt.*;

    import javax.swing.*;

    import java.awt.event.*;

    import java.sql.Connection;

    import java.sql.PreparedStatement;

    import java.sql.ResultSet;

    import java.sql.SQLException;

    import java.sql.Statement;

    public class xingming extends JPanel implements ActionListener{

    JLabel xmlabel1=new JLabel("请输入要查询学生的姓名:");

    JTextField xmf1=new JTextField(10);

    JButton xmbutton1=new JButton("确定");

    JLabel xmlabel2=new JLabel("学号:");

    JTextField xmf2=new JTextField(10);

    JLabel xmlabel3=new JLabel("姓名:");

    JTextField xmf3=new JTextField(10);

    JLabel xmlabel4=new JLabel("性别:");

    JTextField xmf4=new JTextField(10);

    JLabel xmlabel5=new JLabel("jsp分数:");

    JTextField xmf5=new JTextField(10);

    JLabel xmlabel6=new JLabel("java分数:");

    JTextField xmf6=new JTextField(10);

    JLabel xmlabel7=new JLabel("c分数:");

    JTextField xmf7=new JTextField(10);

    JLabel xmlabel8=new JLabel("平均分:");

    JTextField xmf8=new JTextField(10);

    JButton xmbutton2=new JButton("删除");

    JLabel xmlabel10=new JLabel("若要修改该学生信息,请将修改后的信息填入文本框!");

    JButton xmbutton3=new JButton("确认修改");

    JPanel xingming=new JPanel();

    xingming(){

    init();

    setBounds(100,100,600,650);

    setVisible(true);

    }

    void init(){

    setLayout(null);

        xmlabel1.setBounds(50,10,180,20);

        xmf1.setBounds(230,10,150,20);

        xmbutton1.setBounds(500,10,60,30);

        xmlabel2.setBounds(50,60,50,20);

        xmf2.setBounds(120,60,120,20);

        xmlabel3.setBounds(50,90,50,20);

        xmf3.setBounds(120,90,120,20);

        xmlabel4.setBounds(50,120,50,20);

        xmf4.setBounds(120,120,120,20);

        xmlabel5.setBounds(50,150,80,20);

        xmf5.setBounds(120,150,120,20);

        xmlabel6.setBounds(300,60,80,20);

        xmf6.setBounds(400,60,120,20);

        xmlabel7.setBounds(300,90,80,20);

        xmf7.setBounds(400,90,120,20);

        xmlabel8.setBounds(300,120,50,20);

        xmf8.setBounds(400,120,120,20);

        xmbutton2.setBounds(500,150,60,30);

        xmlabel10.setBounds(120,250,320,30);

        xmbutton3.setBounds(480,250,90,30);

        add(xmlabel1);

        add(xmf1);

        add(xmbutton1);

        add(xmlabel2);

        add(xmf2);

        add(xmlabel3);

        add(xmf3);

        add(xmlabel4);

        add(xmf4);

        add(xmlabel5);

        add(xmf5);

        add(xmlabel6);

        add(xmf6);

        add(xmlabel7);

        add(xmf7);

        add(xmlabel8);

        add(xmf8);

        add(xmbutton2);

        add(xmlabel10);

        add(xmbutton3);

        xmbutton1.addActionListener(this);

        xmbutton2.addActionListener(this);

        xmbutton3.addActionListener(this);

     

    }

    public void actionPerformed(ActionEvent e){

    //根据姓名查询某一学生信息ok

    if(e.getSource()==xmbutton1){//查询

    try {

    Connection con = connect.connection();

    String name = xmf1.getText();

    String sql = "select * from student where name='"+name+"'";

    Statement s = con.createStatement();

    ResultSet rs = s.executeQuery(sql);

    if(rs.next()){

    xmf2.setText(rs.getString(1));

    xmf3.setText(name);

    xmf4.setText(rs.getString(3));

    xmf5.setText(rs.getString(4));

    xmf6.setText(rs.getString(5));

    xmf7.setText(rs.getString(6));

    xmf8.setText(rs.getString(7));

    }

    } catch (SQLException e1) {

     

    e1.printStackTrace();

    }

     

    }

    if(e.getSource()==xmbutton2){//删除数据库中该姓名对应的行

    try {

    Connection con = connect.connection();

    String name = xmf1.getText();

    PreparedStatement ps = con.prepareStatement("delete from student where name='"+ name+"'");

    ps.executeUpdate();

    } catch (SQLException e1) {

     

    e1.printStackTrace();

    }

    xmf1.setText("");

    xmf2.setText("");

    xmf3.setText("");

    xmf4.setText("");

    xmf5.setText("");

    xmf6.setText("");

    xmf7.setText("");

    xmf8.setText("");

    }

    if(e.getSource()==xmbutton3){//修改

    String name = xmf1.getText();

    try {

    Connection con = connect.connection();

    PreparedStatement ps = con.prepareStatement("update student set no=?,name=?,sex=?,jsp=?,java=?,c=?,ave=? where name='"+ name+"'");

        ps.setString(1,xmf2.getText());

    ps.setString(2,xmf3.getText());

    ps.setString(3,xmf4.getText());

    ps.setString(4,xmf5.getText());

    ps.setString(5,xmf6.getText());

    ps.setString(6,xmf7.getText());

    ps.setString(7,xmf8.getText());

    ps.executeUpdate();

    } catch (NumberFormatException e1) {

    e1.printStackTrace();

    } catch (SQLException e1) {

                e1.printStackTrace();

    }

    }

    }

    }

     

     

     

    xuehao.java     按学号查询页面

    package stu;

    //package stu;

    import java.awt.*;

    import javax.swing.*;

    import java.awt.event.*;

    import java.sql.Connection;

    import java.sql.PreparedStatement;

    import java.sql.ResultSet;

    import java.sql.SQLException;

    import java.sql.Statement;

    public class xuehao extends JPanel implements ActionListener{

    //学号

    JLabel xhlabel1=new JLabel("请输入要查询学生的学号:");

    JTextField xhf1=new JTextField(10);

    JButton xhbutton1=new JButton("确定");

    JLabel xhlabel2=new JLabel("学号:");

    JTextField xhf2=new JTextField(10);

    JLabel xhlabel3=new JLabel("姓名:");

    JTextField xhf3=new JTextField(10);

    JLabel xhlabel4=new JLabel("性别:");

    JTextField xhf4=new JTextField(10);

    JLabel xhlabel5=new JLabel("jsp分数:");

    JTextField xhf5=new JTextField(10);

    JLabel xhlabel6=new JLabel("java分数:");

    JTextField xhf6=new JTextField(10);

    JLabel xhlabel7=new JLabel("c分数:");

    JTextField xhf7=new JTextField(10);

    JLabel xhlabel8=new JLabel("平均分:");

    JTextField xhf8=new JTextField(10);

    JButton xhbutton2=new JButton("删除");

    JLabel xhlabel9=new JLabel("");

    JLabel xhlabel10=new JLabel("若要修改该学生信息,请将修改后的信息填入文本框!");

    JButton xhbutton3=new JButton("确认修改");

    JPanel xuehao=new JPanel();

    xuehao(){

    init();

    setBounds(100,100,600,650);

    setVisible(true);

    }

    void init(){

     //学号

        setLayout(null);

        xhlabel1.setBounds(50,10,180,20);

        xhf1.setBounds(230,10,150,20);

        xhbutton1.setBounds(500,10,60,30);

        xhlabel2.setBounds(50,60,50,20);

        xhf2.setBounds(120,60,120,20);

        xhlabel3.setBounds(50,90,50,20);

        xhf3.setBounds(120,90,120,20);

        xhlabel4.setBounds(50,120,50,20);

        xhf4.setBounds(120,120,120,20);

        xhlabel5.setBounds(50,150,80,20);

        xhf5.setBounds(120,150,120,20);

        xhlabel6.setBounds(300,60,80,20);

        xhf6.setBounds(400,60,120,20);

        xhlabel7.setBounds(300,90,80,20);

        xhf7.setBounds(400,90,120,20);

        xhlabel8.setBounds(300,120,50,20);

        xhf8.setBounds(400,120,120,20);

        xhbutton2.setBounds(500,150,60,30);

        xhlabel9.setBounds(120,200,300,30);

        xhlabel10.setBounds(120,250,320,30);

        xhbutton3.setBounds(480,250,90,30);

        add(xhlabel1);

        add(xhf1);

        add(xhbutton1);

        add(xhlabel2);

        add(xhf2);

        add(xhlabel3);

        add(xhf3);

        add(xhlabel4);

        add(xhf4);

        add(xhlabel5);

        add(xhf5);

        add(xhlabel6);

        add(xhf6);

        add(xhlabel7);

        add(xhf7);

        add(xhlabel8);

        add(xhf8);

        add(xhbutton2);

        add(xhlabel9);

        add(xhlabel10);

        add(xhbutton3);

            xhbutton1.addActionListener(this);

        xhbutton2.addActionListener(this);

        xhbutton3.addActionListener(this);

    }

    public void actionPerformed(ActionEvent e){

     //根据学号查询某个学生信息ok

    if(e.getSource()==xhbutton1){//查询

    String no = xhf1.getText();

    if(no.length()!=11){

    xhlabel9.setText("学号格式输入错误,请输入的学号为11位!");

    }

    else{

    xhlabel9.setText("");

    try {

    Connection con = connect.connection();

    String sql = "select * from student where no='"+no+"'";

    Statement s = con.createStatement();

    ResultSet rs = s.executeQuery(sql);

    if(rs.next()){

    xhf2.setText(no);

    xhf3.setText(rs.getString(2));

    xhf4.setText(rs.getString(3));

    xhf5.setText(rs.getString(4));

    xhf6.setText(rs.getString(5));

    xhf7.setText(rs.getString(6));

    xhf8.setText(rs.getString(7));

    }

    } catch (SQLException e1) {

     

    e1.printStackTrace();

    }

    }

    }

    if(e.getSource()==xhbutton2){//删除

    try {

    Connection con = connect.connection();

    String no1 = xhf1.getText();

    PreparedStatement ps = con.prepareStatement("delete from student where no='"+ no1+"'");//删除数据库中该学号对应的行

    ps.executeUpdate();

    } catch (SQLException e1) {

     

    e1.printStackTrace();

    }

    xhf1.setText("");

    xhf2.setText("");

    xhf3.setText("");

    xhf4.setText("");

    xhf5.setText("");

    xhf6.setText("");

    xhf7.setText("");

    xhf8.setText("");

    }

    if(e.getSource()==xhbutton3){//修改

    String no1 = xhf1.getText();

    try {

    Connection con = connect.connection();

    PreparedStatement ps = con.prepareStatement("update student set no=?,name=?,sex=?,jsp=?,java=?,c=?,ave=? where no='"+ no1+"'");

        ps.setString(1,xhf2.getText());

    ps.setString(2,xhf3.getText());

    ps.setString(3,xhf4.getText());

    ps.setString(4,xhf5.getText());

    ps.setString(5,xhf6.getText());

    ps.setString(6,xhf7.getText());

    ps.setString(7,xhf8.getText());

    ps.executeUpdate();

    } catch (NumberFormatException e1) {

    e1.printStackTrace();

    } catch (SQLException e1) {

                e1.printStackTrace();

    }

    }

    }

     

    }

     

    test5.java    主函数

    package stu;

     

    public class test5 {

    public static void main(String args[]){

    new home();

    }

     

    }

    展开全文
  • JAVA学生成绩管理系统

    千次下载 热门讨论 2008-06-21 16:59:03
    JAVA做的学生成绩管理系统,SWING做的界面。SQLServer数据库.初学JAVA,如果有见到我程序的朋友,见笑了。偶是菜鸟,对JAVA只有一点认识。 热爱JAVA的朋友,共同学习进步啦!祝愿大家都学好JAVA
  • Java学生成绩管理系统小程序源代码

    热门讨论 2011-08-30 10:27:32
    Java学生成绩管理系统小程序源代码Java学生成绩管理系统小程序源代码Java学生成绩管理系统小程序源代码Java学生成绩管理系统小程序源代码
  • JAVA学生成绩管理系统课程设计报告
  • Java学生成绩管理系统源代码

    热门讨论 2009-07-29 21:33:43
    这是一个简单的Java学生成绩管理系统源代码,应该是学习Java入门的基础,可以和用C想比较
  • java 学生成绩管理系统 源代码

    热门讨论 2009-10-14 18:41:08
    java 学生成绩管理系统 源代码 import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.util.*; import java.lang.*; public class Students.java extends Applet implements ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 18,640
精华内容 7,456
关键字:

java学生成绩管理系统

java 订阅