欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Eclipse+Java+Swing实现学生成绩管理系统的实例代码

程序员文章站 2022-06-19 09:42:30
一、系统介绍本系统实现了用户登录,实现了对学生成绩的增删改查,实现了用户修改密码功能,采用md5加密算法,数据库使用mysql8.0.13,界面良好。二、系统展示1.登录页2.主页面3.查询学生成绩4...

一、系统介绍

本系统实现了用户登录,实现了对学生成绩的增删改查,实现了用户修改密码功能,采用md5加密算法,数据库使用mysql8.0.13,界面良好。

二、系统展示

1.登录页

Eclipse+Java+Swing实现学生成绩管理系统的实例代码

2.主页面

Eclipse+Java+Swing实现学生成绩管理系统的实例代码

3.查询学生成绩

Eclipse+Java+Swing实现学生成绩管理系统的实例代码

4.修改学生成绩

Eclipse+Java+Swing实现学生成绩管理系统的实例代码

5.添加学生成绩

Eclipse+Java+Swing实现学生成绩管理系统的实例代码

6.修改系统密码

Eclipse+Java+Swing实现学生成绩管理系统的实例代码

三、系统实现 student.java

package com.sjsq.model;

import java.util.arraylist;
import java.util.list;

/**
 * 学生实体类
 * @author shuijianshiqing
 *
 */

public class student {

	// 学号
	private string sid;
	// 姓名
	private string sname;
	// 性别
	private string ssex;
	// 学院
	private string scollege;
	private string sc;
	private string smath;
	private string senglish;
	private string schinese;
	private string sjava;

	public student() {
		super();
	}

	public student(string sid, string sname, string ssex, string scollege, string sc, string smath,
			string senglish, string schinese, string sjava) {
		super();
		this.sid = sid;
		this.sname = sname;
		this.ssex = ssex;
		this.scollege = scollege;
		this.sc = sc;
		this.smath = smath;
		this.senglish = senglish;
		this.schinese = schinese;
		this.sjava = sjava;
	}

	public static list<student> students=new arraylist<student>();
	
	public string getsid() {
		return sid;
	}

	public void setsid(string sid) {
		this.sid = sid;
	}

	public string getsname() {
		return sname;
	}

	public void setsname(string sname) {
		this.sname = sname;
	}

	public string getssex() {
		return ssex;
	}

	public void setssex(string ssex) {
		this.ssex = ssex;
	}

	public string getscollege() {
		return scollege;
	}

	public void setscollege(string scollege) {
		this.scollege = scollege;
	}

	public string getsc() {
		return sc;
	}

	public void setsc(string sc) {
		this.sc = sc;
	}

	public string getsmath() {
		return smath;
	}

	public void setsmath(string smath) {
		this.smath = smath;
	}

	public string getsenglish() {
		return senglish;
	}

	public void setsenglish(string senglish) {
		this.senglish = senglish;
	}

	public string getschinese() {
		return schinese;
	}

	public void setschinese(string schinese) {
		this.schinese = schinese;
	}

	public string getsjava() {
		return sjava;
	}

	public void setsjava(string sjava) {
		this.sjava = sjava;
	}

	@override
	public string tostring() {
		return "student [sid=" + sid + ", sname=" + sname + ", ssex=" + ssex + ", scollege=" + scollege + ", sc="
				+ sc + ", smath=" + smath + ", senglish=" + senglish + ", schinese=" + schinese + ", sjava="
				+ sjava + "]";
	}	

}

studentdao.java

package com.sjsq.dao;

import java.io.fileinputstream;
import java.io.fileoutputstream;
import java.io.ioexception;
import java.io.inputstream;
import java.io.outputstream;
import java.sql.resultset;
import java.sql.sqlexception;
import java.util.arraylist;
import java.util.iterator;
import java.util.list;
import com.sjsq.model.student;
import com.sjsq.util.dbutil;

public class studentdao {
	public static int progress;

	// private final string file_path="d:\\student.xls";

	public static studentdao getinstance() {
		studentdao studentdao;
		return studentdao = new studentdao();
	}

	// 查询所有学生的信息
	public resultset queryall() {
		resultset rs = null;
		string sql = "select * from student";
		system.out.println("------查询所有学生信息------");
		system.out.println("sql语句:" + sql);
		dbutil db = new dbutil();
		try {
			rs = db.executequery(sql);
		} catch (sqlexception e) {
			e.printstacktrace();
		}
		return rs;
	}

	// 查询所有学生信息,并且返回list
	public list<student> queryallstudent() {
		list<student> liststudent = new arraylist<student>();
		string sql = "select * from student";
		system.out.println("------查询所有学生信息------");
		system.out.println("sql语句:" + sql);
		dbutil db = new dbutil();
		resultset rs = null;
		try {
			rs = db.executequery(sql);
			while (rs.next()) {
				student studenttmp = new student();
				studenttmp.setsid(rs.getstring("sid"));
				studenttmp.setsname(rs.getstring("sname"));
				studenttmp.setssex(rs.getstring("ssex"));
				studenttmp.setscollege(rs.getstring("scollege"));
				studenttmp.setsc(rs.getstring("sc"));
				studenttmp.setsmath(rs.getstring("smath"));
				studenttmp.setsenglish(rs.getstring("senglish"));
				studenttmp.setschinese(rs.getstring("schinese"));
				studenttmp.setsjava(rs.getstring("sjava"));
				liststudent.add(studenttmp);
			}
		} catch (sqlexception e) {

			e.printstacktrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
			} catch (sqlexception e) {

				e.printstacktrace();
			}
			db.close();
		}
		return liststudent;
	}


	public static int getprogress() {
		return progress;
	}
	
	// 按照条件查询
	public resultset querybycondition(string[] data) {
		resultset rs = null;
		string sql = "select * from student where 1=1";
		int i = 0;
		// 学号
		if (!(data[0].equals(""))) {
			sql += " and sid='" + data[0] + "' ";
		}
		// 姓名
		if (!(data[1].equals(""))) {
			sql += " and sname='" + data[1] + "' ";
		}
		// 省份
		if (!(data[2].equals(""))) {
			sql += " and senglish='" + data[2] + "' ";
		}
		// 性别
		if (!(data[3].equals(""))) {
			sql += " and ssex='" + data[3] + "' ";
		}
		
		system.out.println("------查询所有学生信息------");
		system.out.println("sql语句:" + sql);

		dbutil db = new dbutil();
		try {
			rs = db.executequery(sql);
		} catch (sqlexception e) {

			e.printstacktrace();
		}

		return rs;
	}	
	
	// 插入学生信息,并且返回插入结果
	public boolean insertstudentinformation(student student) {
		dbutil dbutil = new dbutil();
		// 通过student对象设置sid的值
		string sid = student.getsid();
		string sname = student.getsname();
		string ssex = student.getssex();
		string scollege = student.getscollege();
		string sc = student.getsc();
		string smath = student.getsmath();
		string senglish = student.getsenglish();
		string schinese = student.getschinese();
		string sjava = student.getsjava();

		string sql = "insert into student(sid,sname,ssex,scollege,sc,smath,senglish,schinese,sjava)" + 
		"values('" + sid + "','" + sname + "','" + ssex + "','" + scollege+ "','" + sc+ "','" 
				+ smath + "','" + senglish + "','" + schinese + "','" + sjava + "')";
		
		system.out.println("------插入学生信息------");
		system.out.println("sql语句:" + sql);
		
		// 向数据库插入数据语句
		// 定义一个boolean型变量,用于判断插入数据是否成功
		boolean flag = false;
		try {
			// 更新数据库信息
			flag = dbutil.executeupdate(sql);
		} catch (sqlexception e) {
			e.printstacktrace();
		}
		dbutil.close();
		// 返回执行结果
		return flag;

	}

	// 统计同一学号有多少人
	public int queryforsidinformation(string sid) {
		dbutil db = new dbutil();
		// 通过sid查询数据库中是否有相同sid数据
		string sql = "select * from student where sid=" + sid;
		system.out.println("------验证学生学号信息------");
		system.out.println("sql语句:" + sql);
		resultset rs = null;
		int count = 0;
		try {
			// 更新数据库保存到结果集里
			rs = (resultset) db.executequery(sql);
			// 找到相同的count++
			if (rs.next()) {
				count++;
			}
		} catch (sqlexception e) {
			e.printstacktrace();
		}
		// 关闭数据库连接
		db.close();
		// 返回count
		return count;
	}

	// 更新学生信息,这里学号不能更新
	public boolean updatestudentinformation(student student) {
		dbutil dbutil = new dbutil();
		// scollege,sc,smath,senglish,schinese,sjava
		string sql = "update student set sname=" + "'" + student.getsname() + "'" + " ," 
				+ " ssex=" + "'" + student.getssex() + "'" + " ,"
				+ " scollege=" + "'" + student.getscollege() + "' " + " ,"
				+ " sc=" + "'" + student.getsc() + "' " + " ,"
				+ " smath=" + "'" + student.getsmath() + "' " + " ,"
				+ " senglish=" + "'" + student.getsenglish() + "'" + "," 
				+ " schinese=" + "'" + student.getschinese() + "'" + " ," 
				+ " sjava=" + "'" + student.getsjava()+ "'" 
				+ " where" + " sid=" + "'"+ student.getsid() + "'";
		system.out.println("------更新学生信息------");
		system.out.println("sql语句:" + sql);
		
		boolean flag = false;
		try {
			flag = dbutil.executeupdate(sql);
		} catch (sqlexception e) {
			e.printstacktrace();
		}
		return flag;
	}

	// 删除学生信息
	public boolean deletestudentinfobysid(string sid) {
		boolean flag = false;
		string sql = "delete from student where sid=" + "'" + sid + "'";
		
		system.out.println("------删除学生信息------");
		system.out.println("sql语句:" + sql);
		
		dbutil dbutil = new dbutil();
		try {
			flag = dbutil.executeupdate(sql);
		} catch (sqlexception e) {
			e.printstacktrace();
		}
		return flag;
	}
}

loginframe.java

package com.sjsq.view;

import org.jb2011.lnf.beautyeye.ch3_button.bebuttonui;
import java.awt.color;
import java.awt.font;
import java.awt.graphics;
import java.awt.image;
import java.awt.rectangle;
import java.awt.toolkit;
import java.awt.event.actionevent;
import java.awt.event.actionlistener;
import java.awt.event.keyevent;
import java.awt.event.keylistener;

import javax.swing.imageicon;
import javax.swing.jbutton;
import javax.swing.jframe;
import javax.swing.jlabel;
import javax.swing.joptionpane;
import javax.swing.jpanel;
import javax.swing.jpasswordfield;
import javax.swing.jtextfield;
import javax.swing.timer;
import javax.swing.uimanager;

import com.sjsq.model.user;
import com.sjsq.util.md5util;
import com.sjsq.dao.userdao;

public class loginframe extends jframe implements actionlistener {
	public static string uname = null;
	public static string pwd = null;
	string username, password, login, quit;

	// 登录标签
	private jlabel loginjlabel;
	private jpanel jcontentpane = null;
	private jbutton jbuttonlogin = null;
	private jbutton jbuttonexit = null;
	private jtextfield jtextfieldusername = null;
	private jtextfield jtextfieldpassword = null;
	// 登录用户名
	static int storeuserid;
	// 图片
	public jlabel jlabel_image = null;
	// 登录用户名
	public static string storeuserame = null;
	// 登录密码
	public static string storeuserpassword = null;
	// 重新登陆标记
	static boolean reload = true;
	private jlabel jlabelusername = null;
	private jlabel jlabelpassword = null;

	int index;
	
	public loginframe() {
			// 设置背景
			setforeground(new color(255, 255, 255));
			this.setresizable(false);
			this.setsize(800, 500);
			this.settitle("学生成绩管理系统");
			
			this.setlocationrelativeto(null);
			try {
				uimanager.setlookandfeel("com.sun.java.swing.plaf.windows.windowslookandfeel");// 使用windows外观
			} catch (exception e) {
				e.printstacktrace();
			}
			
			loginjlabel = new jlabel("学生成绩管理系统");
			font font = new font("微软雅黑",font.bold,40);
			loginjlabel.setfont(font);
			loginjlabel.setbounds(220,100,650, 50);
			loginjlabel.setforeground(color.dark_gray);
			getcontentpane().add(loginjlabel);

			font font2 = new font("微软雅黑",font.bold,15);
			jlabelpassword = new jlabel();
			jlabelpassword.setfont(font2);
			jlabelpassword.setbounds(new rectangle(300, 250, 71, 29));
			jlabelpassword.settext("用户名:");
			jlabelusername = new jlabel();
			jlabelusername.setbounds(new rectangle(300, 300, 71, 29));
			jlabelusername.setfont(font2);
			jlabelusername.settext("密码:");
			
			// 账号输入框
			jtextfieldusername = new jtextfield(20);
			jtextfieldusername.setbounds(new rectangle(360, 250, 154, 33));
			// 密码输入框
			jtextfieldpassword = new jpasswordfield();
			jtextfieldpassword.setbounds(new rectangle(360, 300, 154, 33));
			
			// 登录
			jbuttonlogin = new jbutton();
			jbuttonlogin.setbounds(new rectangle(320, 380, 78, 26));
			jbuttonlogin.settext("登录");
			jbuttonlogin.setui(new bebuttonui()
					.setnormalcolor(bebuttonui.normalcolor.green));
			// 回车登录
			getrootpane().setdefaultbutton(jbuttonlogin);

			// 退出
			jbuttonexit = new jbutton();
			jbuttonexit.setui(new bebuttonui()
					.setnormalcolor(bebuttonui.normalcolor.lightblue));
			jbuttonexit.setbounds(new rectangle(420, 380, 78, 26));
			jbuttonexit.settext("退出");
			
			// 包含所有的元素
			jcontentpane = new jpanel();
			jcontentpane.setlayout(null);
			jcontentpane.add(jlabelusername, null);
			jcontentpane.add(jlabelpassword, null);
			jcontentpane.add(jbuttonlogin, null);
			jcontentpane.add(jbuttonexit, null);
			jcontentpane.add(jtextfieldusername, null);
			jcontentpane.add(jtextfieldpassword, null);
			getcontentpane().add(jcontentpane);
			
			jtextfieldusername.addkeylistener(new keylistener() {
				@override
				public void keypressed(keyevent e) {

				}
				@override
				public void keyreleased(keyevent e) {

				}
				@override
				public void keytyped(keyevent e) {
					if(e.getkeychar() == keyevent.vk_enter){
						jtextfieldpassword.requestfocus();
					}
				}
			});

			jtextfieldpassword.addkeylistener(new keylistener() {
				@override
				public void keytyped(keyevent e) {

				}
				@override
				public void keyreleased(keyevent e) {

				}
				@override
				public void keypressed(keyevent e) {
					if(e.getkeychar() == keyevent.vk_enter){
						username = jtextfieldusername.gettext();
						password = md5util.string2md5(jtextfieldpassword.gettext());

						user user = new user();
						user.setusername(username);
						user.setpassword(password);
						string s=user.getusername();
						string p=jtextfieldpassword.gettext();
						userdao userdao = new userdao();
						int choice = 0;
						if(!userdao.checkuser(user)) {
							joptionpane.showmessagedialog(null, "用户名和密码错误","消息提示",joptionpane.warning_message);
						}else {
							setvisible(false);
							mainmenuframe mm = new mainmenuframe();
							uname = s;
							pwd=p;
						}
					}
				}
			});

			this.setdefaultcloseoperation(exit_on_close);
			this.setvisible(true);

			// 添加监控
			jtextfieldusername.addactionlistener(this);
			jtextfieldpassword.addactionlistener(this);
			jbuttonlogin.addactionlistener(this);
			jbuttonexit.addactionlistener(this);
		}


	@override
	public void actionperformed(actionevent e) {

		// 获取账号和密码
		username = jtextfieldusername.gettext();
		password = md5util.string2md5(jtextfieldpassword.gettext());

		user user = new user();
		user.setusername(username);
		user.setpassword(password);
		string s = user.getusername();
		string p = jtextfieldpassword.gettext();
		userdao userdao = new userdao();
		int choice = 0;

		if (e.getsource() == jbuttonlogin) {
			if (!userdao.checkuser(user)) {
				joptionpane.showmessagedialog(null, "用户名和密码错误", "消息提示", joptionpane.warning_message);
			} else {
				setvisible(false);
				mainmenuframe mm = new mainmenuframe();
				uname = s;
				pwd = p;
			}
		} else if (e.getsource() == jbuttonexit) {
			system.exit(0);
		}
	}
	
	// 测试
	public static void main(string[] args) {
		new loginframe();
	}
}

mainmenuframe.java

package com.sjsq.view;

import java.awt.font;
import java.awt.rectangle;
import java.awt.event.actionevent;
import java.awt.event.actionlistener;
import java.awt.event.windowadapter;
import java.awt.event.windowevent;

import javax.swing.imageicon;
import javax.swing.jbutton;
import javax.swing.jframe;
import javax.swing.jmenubar;
import javax.swing.jmenuitem;
import javax.swing.jpanel;
import javax.swing.jscrollpane;
import javax.swing.jtextarea;

import org.jb2011.lnf.beautyeye.ch3_button.bebuttonui;

/*
 * 登陆成功后主界面
 */
public class mainmenuframe extends jframe implements actionlistener {
	private jframe mainmenu;
	private jtextarea text;
	// 标题栏(关于)
	private jmenubar menubar1;
	private jmenuitem aboutsystem;

	public mainmenuframe() {

		mainmenu();
	}

	public void mainmenu() {
		mainmenu = new jframe("极客大学学生管理系统");
		setlocationrelativeto(null);// 将容器显示在屏幕*
		mainmenu.setsize(850, 650);

		mainmenu.getcontentpane().add(new jscrollpane(text));

		jpanel jcontentpane = new jpanel();
		jcontentpane.setlayout(null);

		// 查询学生按钮
		jbutton jbuttonselect = new jbutton();
		jbuttonselect.setbounds(new rectangle(320, 100, 100, 52));
		jbuttonselect.settext("查询学生");
		jbuttonselect.setui(new bebuttonui().setnormalcolor(bebuttonui.normalcolor.lightblue));
		getrootpane().setdefaultbutton(jbuttonselect);// 回车登录

		// 添加学生按钮
		jbutton jbuttonadd = new jbutton();
		jbuttonadd.setui(new bebuttonui().setnormalcolor(bebuttonui.normalcolor.lightblue));
		jbuttonadd.setbounds(new rectangle(320, 200, 100, 52));
		jbuttonadd.settext("添加学生");

		// 修改密码按钮
		jbutton jbuttonalterpwd = new jbutton();
		jbuttonalterpwd.setui(new bebuttonui().setnormalcolor(bebuttonui.normalcolor.lightblue));
		jbuttonalterpwd.setbounds(new rectangle(320, 300, 100, 52));
		jbuttonalterpwd.settext("密码修改");

		// 退出系统按钮
		jbutton jbuttonexit = new jbutton();
		jbuttonexit.setui(new bebuttonui().setnormalcolor(bebuttonui.normalcolor.lightblue));
		jbuttonexit.setbounds(new rectangle(320, 400, 100, 52));
		jbuttonexit.settext("退出系统");

		jcontentpane.add(jbuttonselect, null);
		jcontentpane.add(jbuttonadd, null);
		jcontentpane.add(jbuttonalterpwd, null);
		jcontentpane.add(jbuttonexit, null);

		// 添加label到frame
		mainmenu.getcontentpane().add(jcontentpane);
		// 设置字体
		font font = new font("微软雅黑", font.bold, 16);
		// 标题栏
		menubar1 = new jmenubar();

		// aboutsystem = new jmenuitem("关于本系统",new
		// imageicon("src/images/icons/about.png"));
		aboutsystem = new jmenuitem("关于本系统");
		aboutsystem.setmnemonic('h');

		menubar1.add(aboutsystem);

		// 查询学生
		jbuttonselect.addactionlistener(new actionlistener() {

			@override
			public void actionperformed(actionevent e) {
				system.out.println("------查询学生-----");
				querystudentinfo querystudentinfo = new querystudentinfo();
			}
		});

		// 添加学生
		jbuttonadd.addactionlistener(new actionlistener() {

			@override
			public void actionperformed(actionevent e) {
				system.out.println("------添加学生-----");
				addstudentinfo addstudentinfo = new addstudentinfo();
			}
		});

		// 修改密码
		jbuttonalterpwd.addactionlistener(new actionlistener() {

			@override
			public void actionperformed(actionevent e) {
				system.out.println("------修改密码-----");
				modifypasswordinfo modifypasswordinfo = new modifypasswordinfo();
			}
		});

		// 退出系统
		jbuttonexit.addactionlistener(new actionlistener() {

			@override
			public void actionperformed(actionevent e) {
				system.out.println("------退出系统-----");
				system.exit(1);
			}
		});

		// 关于系统
		aboutsystem.addactionlistener(new actionlistener() {

			@override
			public void actionperformed(actionevent e) {
				system.out.println("------关于系统------");
				aboutsystem aboutsystem = new aboutsystem();
			}
		});

		// 关闭窗口监控
		mainmenu.addwindowlistener(new windowadapter() {
			public void windowclosing(windowevent arg0) {
				system.exit(1);
			}
		});

		mainmenu.setjmenubar(menubar1);
		mainmenu.setvisible(true);
		// mainmenu.setlocation(250, 50);
		mainmenu.setlocationrelativeto(null);
		aboutsystem.addactionlistener(this);
	}

	// 主函数测试
	public static void main(string[] args) {
		new mainmenuframe();

	}

	@override
	public void actionperformed(actionevent arg0) {
	}

}

到此这篇关于eclipse+java+swing实现学生成绩管理系统的文章就介绍到这了,更多相关eclipse+java+swing实现学生成绩管理系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!