Java课设 学生基本信息管理

一、项目简介

功能描述:

用java实现学生信息的管理,其中录入的数据包括:学号、姓名、年龄、性别、学院、班级、生日等,并且能够实现对学生信息的添加、修改、删除、查看功能。

需求分析:

学生信息管理系统是一个教育单位不可缺少的部分。一个功能齐全、简单易用的信息管理系统不但能有效地减轻学校相关工作人员的工作负担,它的内容对于学校的决策者和管理者来说都至关重要。所以学生信息管理系统应该能够为用户提供充足的信息和快捷的查询手段。但一直以来人们使用传统人工的方式管理文件档案、统计和查询数据,这种管理方式存在着许多缺点,如:效率低、保密性差、人工的大量浪费;另外时间一长,将产生大量的文件和数据,这对于查找、更新和维护都带来了不少困难。随着科学技术的不断提高,计算机科学日渐成熟,其强大的功能已为人们深刻认识,它已进入人类社会的各个领域并发挥着越来越重要的作用。

参考git地址或博客地址

https://blog.csdn.net/qq_61827376/article/details/124470583?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168654375416800222892994%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=168654375416800222892994&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-124470583-null-null.142^v88^insert_down1,239^v2^insert_chatgpt&utm_term=java%E8%AF%BE%E7%A8%8B%E8%AE%BE%E8%AE%A1&spm=1018.2226.3001.4187

团队git链接

Java课设: Java课设--学生基本信息管理

git提交记录

二、功能架构图

团队成员负责模块:

序号

完成功能与任务

描述

组长

功能版块

实现增加、删除、查询、更改功能

代码整合

整合实现代码,进行运行和纠错。

组员

登录界面

JavaSwing技术(监听器,组件),设置登录的账户与密码

学生信息设置

JavaSwing,定义学生姓名、学号等信息

三、任务简述

实现对学生信息的添加、修改、删除、查看功能。

1. 完成的任务与功能

学生登录窗口,采用了基于管理窗口,即主界面的对话框实现,实现方法如下:

1)定义学生信息。

2)定义登录所需要的面板和组件。

3)实现密码校验。

4)进入学生信息管理界面。

修改学生信息的界面,通过模式对话,实现方法如下:

1)定义修改学生信息的相关组件。

2)把组件添加到窗体。

3)实现添加、查询内容。

4)调用修改学生信息的界面的方法。

5)修改学生信息。

6)完成相应功能。

四、详细代码

1.student类

package 课设2;





class User{

private String userId;

private String password;

public String getUserId(){

return userId;

}

public void setUserId(String userId){

this.userId=userId;

}

public String getPassword(){

return password;

}

public void setPassword(String password){

this.password=password;

}

}

public class Student extends User{

private static final String College = null;

private String id;

private String name;

private String sex;

private String age;

private String college;

private String major;

private String birthday;

private String pc;

private String phone;

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 getSex(){

return sex;

}

public void setSex(String sex){

this.sex=sex;

}

public String getAge(){

return age;

}

public void setAge(String age){

this.age=age;

}

public String getCollege(){

return college;

}

public void setCollege(String college){

this.college=college;

}



public String getMajor(){

return major;

}

public void setMajor(String major){

this.major=major;

}

public String getBirthday(){

return birthday;

}

public void setBirthday(String birthday){

this.birthday=birthday;

}

public String getPc(){

return pc;

}

public void setPc(String pc){

this.pc=pc;

}

public String getPhone(){

return phone;

}

public void setPhone(String phone){

this.phone=phone;

}

}

2.loginGUI类

package 课设2;


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.ButtonGroup;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

public class LoginGUI{
	private JFrame jf;
	//水平box
	private Box center=Box.createVerticalBox();
	//学号的JPanel
	private JPanel idPanel=new JPanel();
	//密码的JPanel
	private JPanel passwordPanel=new JPanel();
	private JLabel lUserId=new JLabel("用户名");
	private JTextField tUserId=new JTextField(15);
	private JLabel lPassword=new JLabel("密   码");
	private JPasswordField tPassword=new JPasswordField(15);
	//按钮的JPanel
	private JPanel buttonPanel=new JPanel();
	private JButton bLogin=new JButton("登录");
	private JButton bCancel=new JButton("取消");
	//设置运行时窗口的大小
	Dimension faceSize=new Dimension(350,150);
	//获得屏幕的大小
	Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
	public void init(){
		jf=new JFrame("学生信息管理系统");
		//设置JFrame的名称
		jf.setTitle("登录");
		//将lUserId,tUserId放在idPanel中,idPanel默认水平放置
		idPanel.add(lUserId);
		idPanel.add(tUserId);
		passwordPanel.add(lPassword);
		passwordPanel.add(tPassword);
		center.add(idPanel);
		center.add(passwordPanel);
		buttonPanel.add(bLogin);
		buttonPanel.add(bCancel);
		//登录按钮的监听器
		bLogin.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				String userId=tUserId.getText();
				String password=String.valueOf(tPassword.getPassword());
				//开启接受数据的线程
				if(userId.trim().equals("")||userId==null||password.trim().equals("")||password==null){
					JOptionPane.showMessageDialog(jf,"用户名或密码不能为空!","提示",JOptionPane.WARNING_MESSAGE);
				}else{
					if(userId.equals("课设")&&password.equals("123456")){//真正的账号密码
						new StudentManageView().init();
					}else{
						loginFailure();
					}
				}
			}
			
		});
		//取消按钮的监听器
		bCancel.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				System.exit(0);
			}
		});
		center.add(buttonPanel);
		jf.add(center);
		jf.pack();
		//设置JFame运行时的大小
		jf.setSize(faceSize);
		//设置JFame运行时的位置
		jf.setLocation((int)(screenSize.width-faceSize.getWidth())/2,(int)(screenSize.height-faceSize.getHeight())/2);
		//设置JFrame不可最大化
		jf.setResizable(false);
		//设置JFrame单机X时结束程序
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//设置JFrame可见
		jf.setVisible(true);
	}
	public void loginFailure(){
		JOptionPane.showMessageDialog(jf, "用户名或密码输入不正确!","提示",JOptionPane.WARNING_MESSAGE);
	}
	public static void main(String args[])throws Exception{
		new LoginGUI().init();
	}
}
class MyJTable extends JTable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -3083638370004874364L;
	public MyJTable(TableModel dm){
		super(dm);
	}
	//设置表格不可编辑
	public boolean isCellEditable(int rowIndex,int columnIndex){
		return false;
	}
}
class StudentService{
	private Student[] students=new Student[50];
	//添加学生信息
	public void insert(Student s){
		for(int i=0;i<students.length;i++){
			if(students[i]==null){
				students[i]=s;
				System.out.println("添加成功!");
				break;
			}
		}
	}
	//删除学生信息
	public int delete(String userId){
		int flag=0;
		for(int i=0;i<students.length;i++){
			if(students[i]!=null){
				if(students[i].getUserId().equals(userId)){
					students[i]=null;
					System.out.print("删除成功!");
					flag=1;
					break;
				}
			}
		}
		return flag;
	}
	//修改学生信息
	public void update(Student s){
		String userId=s.getUserId();
		for(int i=0;i<students.length;i++){
			if(students[i]!=null){
				if(students[i].getUserId().equals(userId)){
					students[i].setId(s.getId());
					students[i].setName(s.getName());
					students[i].setSex(s.getSex());
					students[i].setAge(s.getAge());
					students[i].setCollege(s.getCollege());
					students[i].setMajor(s.getMajor());
					students[i].setBirthday(s.getBirthday());
					students[i].setPc(s.getPc());
					students[i].setPhone(s.getPhone());
				}
			}
		}
	}
	//按学号查询
	public Student selectById(String userId){
		for(Student s:students){
			if(s!=null){
				if(s.getUserId().equals(userId)){
					return s;
				}
			}
		}
		return null;
	}
	//查询所有学生信息
	public Student[] selectAll(){
		return students;
	}
}
  class StudentManageView {

	private JFrame jf=new JFrame("学生信息管理系统");
	Dimension faceSize=new Dimension(800,600);
	private Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
	//按学号查询
	private JPanel pSelect=new JPanel();
	private JLabel lSelect=new JLabel("学号");
	private JTextField tSelect=new JTextField(15);
	private JButton bSelect=new JButton("查询");
	//查询结果放在一个JTable
	private MyJTable table;
	private DefaultTableModel tableModel;
	private JScrollPane tableScrollPane;
	private Object[] tableTitle={"学号","姓名","性别","年龄","学院:","专业班级:","出生日期:","政治面貌:","联系方式:"};
	private Object[][]tableData={new Object[]{""}};
	//对学生信息进行管理的添加、删除、修改按钮
	private JPanel buttonPanel=new JPanel();
	private JButton insert=new JButton("添加");
	private JButton delete=new JButton("删除");
	private JButton update=new JButton("修改");
	//单机添加、修改时弹出的对话框
	private JDialog dialog=new JDialog(jf,"学生管理");
	private Box box=Box.createVerticalBox();

	private JPanel pId=new JPanel(new FlowLayout(FlowLayout.LEFT));
	private JPanel pName=new JPanel(new FlowLayout(FlowLayout.LEFT));
	private JPanel pSex=new JPanel(new FlowLayout(FlowLayout.LEFT));
	private JPanel pAge=new JPanel(new FlowLayout(FlowLayout.LEFT));
	private JPanel pCollege=new JPanel(new FlowLayout(FlowLayout.LEFT));
	private JPanel pMajor=new JPanel(new FlowLayout(FlowLayout.LEFT));
	private JPanel pBirthday=new JPanel(new FlowLayout(FlowLayout.LEFT));
	private JPanel pPc=new JPanel(new FlowLayout(FlowLayout.LEFT));
	private JPanel pPhone=new JPanel(new FlowLayout(FlowLayout.LEFT));
	
	private JLabel lId=new JLabel("学 号");
	private JLabel lName=new JLabel("姓 名");
	
	private JLabel lSex=new JLabel("性 别");
	private JLabel lAge=new JLabel("年 龄");
	private JLabel lCollege = new JLabel("学院:");
	private JLabel lMajor = new JLabel("专业班级:");
	private JLabel lBirthday = new JLabel("出生日期:");
	private JLabel lPc = new JLabel("政治面貌:");
	private JLabel lPhone = new JLabel("联系方式:");	
	
	private JTextField tId=new JTextField(15);
	private JTextField tName=new JTextField(15);
	private ButtonGroup bSex=new ButtonGroup();
	private JRadioButton boy=new JRadioButton("男");
	private JRadioButton girl=new JRadioButton("女");
	private JTextField tAge=new JTextField(15);
	private JTextField tCollege=new JTextField(15);
	private JTextField tMajor=new JTextField(15);
	private JTextField tBirthday=new JTextField(15);
	private JTextField tPc=new JTextField(15);
	private JTextField tPhone=new JTextField(15);
	
	
	private JPanel pButton=new JPanel();
	private JButton confirm=new JButton("确认");
	private JButton cancel=new JButton("取消");
	private StudentService service=new StudentService();
	//用于标记是添加还是修改
	private String id;
	void init(){
		pSelect.add(lSelect);
		pSelect.add(tSelect);
		pSelect.add(bSelect);
		//查询按钮的监听器
		bSelect.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				String userId=tSelect.getText().trim();
				if(userId.equals("")){
					Student[] student=service.selectAll();
					clearTable();
					for(Student s:student){
						insertTable(s);
					}
				}else{
					Student s=service.selectById(userId);
					if(s!=null){
						clearTable();
						insertTable(s);
					}else{
						selectFailure();
					}
				}
			}
		
	});
		//table
		tableModel=new DefaultTableModel(tableData,tableTitle);
		table=new MyJTable(tableModel);
		tableScrollPane=new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED  );
		//button
		buttonPanel.add(insert);
		buttonPanel.add(delete);
		buttonPanel.add(update);
		//添加按钮的监听器
		insert.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
		//	
				id=null;
				tId.setText("");
				tId.setEditable(true);
				tName.setText("");
				bSex.clearSelection();
				tAge.setText("");
				tCollege.setText("");
				tMajor.setText("");
				tBirthday.setText("");
				tPc.setText("");
				tPhone.setText("");
				dialog.setVisible(true);
				
			}
		});
		//删除按钮的监听器
		delete.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				//获得选择删除的行号数组
				int[] selected=table.getSelectedRows();
				//如果selected的长度为0,说明没有选择要删除的
				if(selected.length==0){
					JOptionPane.showMessageDialog(jf, "请选择要删除的信息!","提示",JOptionPane.WARNING_MESSAGE );
				}else{
					//提示是否要进行删除
					int flag=JOptionPane.showConfirmDialog(jf, "确认删除吗?","提示",JOptionPane.WARNING_MESSAGE );
					//如果选择是,则进行删除
					if(flag==JOptionPane.OK_OPTION ){
						for(int i=selected.length-1;i>=0;i--){
							service.delete((String)tableModel.getValueAt(selected[i], 0));
							tableModel.removeRow(selected[i]);
						}
					}
				}
			}
		});
		//修改按钮的监听器
		 update.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
		    int row=table.getSelectedRow();
		    //如果要进行修改,就将id=要修改的学号
		    id=String.valueOf(table.getValueAt(row, 0));
		    //设置tId的内容
		    tId.setText(id);
		    //设置tId不可修改
		    tId.setEditable(false);
		    tName.setText(String.valueOf(table.getValueAt(row, 1)));
		    String sex=(String) table.getValueAt(row, 2);
		    //如果性别是"男",则将单选框中的男选中,否则选中女
		    if(sex.equals("男")){
		    	bSex.setSelected(boy.getModel(),true);
		    }else{
		    	bSex.setSelected(girl.getModel(),true);
		    }
		    tAge.setText(String.valueOf(table.getValueAt(row, 3)));
		    tCollege.setText(String.valueOf(table.getValueAt(row, 4)));
		    tMajor.setText(String.valueOf(table.getValueAt(row, 5)));
		    tBirthday.setText(String.valueOf(table.getValueAt(row, 6)));
		    tPc.setText(String.valueOf(table.getValueAt(row, 7)));
		    tPhone.setText(String.valueOf(table.getValueAt(row, 8)));
		    //设置dialog可见
		    dialog.setVisible(true);
		    }
});
		jf.setLayout(new BorderLayout());
		//设置pSelect在jf的北面
		jf.add(pSelect,BorderLayout.NORTH);
		//设置pSelect在jf的中心
		jf.add(tableScrollPane,BorderLayout.CENTER );
		//设置pSelelct在jf的南面
		jf.add(buttonPanel,BorderLayout.SOUTH);
		jf.pack();
		jf.setSize(faceSize);
		jf.setLocation((int)(screenSize.width-faceSize.getWidth())/2,(int)(screenSize.height-faceSize.getHeight())/2);
		jf.setResizable(false);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setVisible(true);

		pId.add(lId);
		pId.add(tId);
		pName.add(lName);
		pName.add(tName);
		pSex.add(lSex);
		bSex.add(boy);
		bSex.add(girl);
		pSex.add(boy);
		pSex.add(girl);
		pAge.add(lAge);
		pAge.add(tAge);
		pCollege.add(lCollege);
		pCollege.add(tCollege);
		pMajor.add(lMajor);
		pMajor.add(tMajor);
		pBirthday.add(lBirthday);
		pBirthday.add(tBirthday);
		pPc.add(lPc);
		pPc.add(tPc);
		pPhone.add(lPhone);
		pPhone.add(tPhone);
		
		pButton.add(confirm);
		pButton.add(cancel);
		//确定按钮的监听器
		confirm.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
			Student student=new Student();
			student.setUserId(tId.getText());
			student.setPassword(tId.getText());
			student.setId(tId.getText());
			student.setName(tName.getText());
			String sex=null;
			if(boy.isSelected()){
				sex="男";
			}
			if(girl.isSelected()){
				sex="女";
			}
			student.setSex(sex);
			student.setAge(tAge.getText());
			student.setCollege(tCollege.getText());
			student.setMajor(tMajor.getText());
			student.setBirthday(tBirthday.getText());
			student.setPc(tPc.getText());
			student.setPhone(tPhone.getText());
			if(id!=null){
				service.update(student);
			}else{
				service.insert(student);
			}
			dialog.dispose();
			}
		});
		//取消按钮的监听器
		cancel.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				dialog.dispose();
			}
		});
		box.add(pId);
		box.add(pName);
		box.add(pSex);
		box.add(pAge);
		box.add(pCollege);
		box.add(pMajor);
		box.add(pBirthday);
		box.add(pPc);
		box.add(pPhone);
		box.add(pButton);
		box.add(pButton);
		dialog.add(box);
		dialog.setBounds((int)(screenSize.width-280)/2,(int)(screenSize.height-300)/2,280,350);
	}
		public void insertTable(Student student){
			if(student!=null){
				String[]newCell=new String[9];
				newCell[0]=student.getId();
				newCell[1]=student.getName();
				newCell[2]=student.getSex();
				newCell[3]=student.getAge();
				newCell[4]=student.getCollege();
				newCell[5]=student.getMajor();
				newCell[6]=student.getBirthday();
				newCell[7]=student.getPc();
				newCell[8]=student.getPhone();
				
				tableModel.addRow(newCell);
			}
		}
		public void clearTable(){
			int rows=tableModel.getRowCount();
			for(int i=rows-1;i>=0;i++){
				tableModel.removeRow(i);
			}
		}
		public void selectFailure(){
			JOptionPane.showMessageDialog(jf,"不存在该学号的学生!","提示",JOptionPane.WARNING_MESSAGE );
		}
}

运行展示

登录

输入错误密码

输入正确密码

添加学生信息

 查询学生信息

删除学生信息

修改学生信息

五、心得体会

这次为期一周的课程设计让我对java有了新的认识,首先我接触了很多上课见过但没有实际用过的类和方法,让我对编程有了许多新的思想。

在课程设计这一段时间,使我收获了很多在课本上无法学习到的知识,尤其是需求分析和eclipse熟练的使用。比较大一学习与完成的课设,Java带有很强的实用性,真的体会到了学习与实践相结合,由于课程比较紧,也没能做出优秀的内容,我们小组整体比较中规中矩,也没有很多创新点,希望能在接下来的时间中继续努力,做出更多优秀有亮点的设计。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值