大一项目实训—学生成绩管理系统

<>项目实训总结

由于自己大一在Java课中没有好好听讲,导致项目实训中完全是一边学习一边敲代码。但自己付出了很多努力,早上8.30起床,晚上2,3点才睡甚至通宵,虽然做的都是很基础的东西,但上课不好好听课就得努力(惨重代价)。

<>主要负责

一、主面板的设计
二 、学生信息,教师信息,学生成绩的管理

<>部分代码

主要用到了学生信息(studentinfo)学生成绩(studentgrade)两个Mysql的表,
功能是对表中进行增删改,即录入学生成绩,修改学生成绩,删除学生成绩等。
然后就是各种表的外键的确很麻烦,在录入学生成绩时,需要判断该学生是否存在,以及修改学生成绩时判断是否有改科目等等限制。

<>奋发图强

学习Java还比较浅,在暑假会好好恶补一番基础。队友很多次帮我修改bug了,实在过意不去。下学期PHP,Mysql还有企业级web应用开发一定要好好学习。
package StudentManage; import java.awt.Button; import java.awt.Choice; import
java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridLayout;
import java.awt.Label; import java.awt.Panel; import java.awt.TextField; import
java.awt.Toolkit; import java.awt.event.ActionEvent; import
java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import
java.awt.event.WindowEvent; import java.sql.ResultSet; import
java.sql.SQLException; import java.util.Vector; import javax.swing.JFrame;
import javax.swing.JOptionPane; import javax.swing.JScrollPane; import
javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class
GradeChange extends JFrame implements ActionListener { Label sid1, sid2, sb1,
empty,empty1,empty2,empty3,classcode; Label name1, subject1, studentgrade1 ;
TextField sid11, sid22; TextField name2, subject2, studentgrade2,classcode1;
Choice choice; JFrame jFrame; Button look, refresh, delete, submit, reset,
exit, add, change, help,delete1,reset1,submit1,back; String string; ResultSet
rs = null; // 查询用模板及滚动界面 DefaultTableModel model; JScrollPane check, check1;
JTable jTable1, jTable2; Panel panel0,panel1,panel2,panel3,panel4; public
GradeChange() { super("学生成绩管理"); toppanel(); table(DBHelper.query("select *
from studentgrade order by sid ")); // 初始面板显示信息 mainpanel(); // // 设置监听器
setSize(450, 320);// 设置大小、可视化、退出 setVisible(true); Dimension faceSize = new
Dimension(550, 320); Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation((int)
(screenSize.width - faceSize.getWidth()) / 2, (int) (screenSize.height -
faceSize.getHeight()) / 2); // 退出 exit.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) { dispose(); } });
this.addWindowListener(new WindowAdapter() { @Override public void
windowClosing(WindowEvent e) { dispose(); } }); } //顶头的查询刷新框 private void
toppanel() { panel1=new Panel(); sid1 = new Label("学生编号:"); sid11 = new
TextField(15); look = new Button("查询"); refresh = new Button("刷新"); exit = new
Button("退出"); panel1.setVisible(true); add(panel1, "North");
panel1.add(sid1);// 添加至panel1 panel1.add(sid11); panel1.add(look);
panel1.add(refresh); panel1.add(refresh); panel1.add(exit);
look.addActionListener(this); refresh.addActionListener(this); } //三个功能的框
private void mainpanel() { panel0=new Panel(); delete1 = new Button("删除");
submit1= new Button("添加"); reset1 = new Button("修改"); panel0.add(submit1);
panel0.add(delete1); panel0.add(reset1); panel0.setVisible(true); add(panel0,
"South"); delete1.addActionListener(new ActionListener() { //删除 框 public void
actionPerformed(ActionEvent e) { panel4(); } }); submit1.addActionListener(new
ActionListener() { //增加 框 public void actionPerformed(ActionEvent e) {
panel3(); } }); reset1.addActionListener(new ActionListener() { //删除修改框 public
void actionPerformed(ActionEvent e) { panel2(); } }); setVisible(true); } //修改框
private void panel2() { table(DBHelper.query("select * from studentgrade order
by sid ")); // 初始面板显示信息 remove(panel0); panel2 = new Panel(); // 设置 输入框
panel2.setLayout(new GridLayout(4,3)); sid2 = new Label("学生编号"); subject1 = new
Label("科目"); studentgrade1 = new Label("成绩"); empty = new Label(""); empty1=new
Label(""); empty2=new Label(""); reset = new Button("修改"); back=new
Button("返回"); sid22 = new TextField(); subject2 = new TextField();
studentgrade2 = new TextField(); panel2.add(sid2); panel2.add(sid22);
panel2.add(empty); panel2.add(subject1); panel2.add(subject2);
panel2.add(empty1); panel2.add(studentgrade1); panel2.add(studentgrade2);
panel2.add(empty2); panel2.add(reset); panel2.add(back);
reset.addActionListener(this); panel2.setVisible(true); add(panel2, "South");
back.addActionListener(new ActionListener() { //返回选择功能界面 public void
actionPerformed(ActionEvent e) { table(DBHelper.query("select * from
studentgrade order by sid ")); // 初始面板显示信息 remove(panel2); mainpanel(); } });
setVisible(true); } //添加框 private void panel3() { table(DBHelper.query("select
* from studentgrade order by sid ")); // 初始面板显示信息 remove(panel0); panel3 = new
Panel(); // 设置 输入框 panel3.setLayout(new GridLayout(5,3)); sid2 = new
Label("学生编号"); subject1 = new Label("科目"); studentgrade1 = new Label("成绩");
empty = new Label(""); empty1=new Label(""); empty2=new Label(""); empty3=new
Label(""); classcode=new Label("教学班"); submit = new Button("添加"); back=new
Button("返回"); sid22 = new TextField(); subject2 = new TextField();
classcode1=new TextField(); studentgrade2 = new TextField(); panel3.add(sid2);
panel3.add(sid22); panel3.add(empty); panel3.add(subject1);
panel3.add(subject2); panel3.add(empty1); panel3.add(studentgrade1);
panel3.add(studentgrade2); panel3.add(empty2); panel3.add(classcode);
panel3.add(classcode1); panel3.add(empty3); panel3.add(submit);
panel3.add(back); submit.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) { String s4=null,s5=null; String
s1=sid11.getText(); String s2 =sid22.getText(); String subject=
subject2.getText();//底部 // jdbc数据的添加操作 // name2, subject2, studentgrade2,
classcode2, adminiclass2; if (sid22.getText().length() ==
0||subject2.getText().length()==0||studentgrade2.getText().length()==0||classcode1.getText().length()==0
){ JOptionPane.showMessageDialog(null, "请正确输入所有信息!"); } else { try {
rs=DBHelper.query("select name,adminiclass from studentinfo where sid="+s2);
while (rs.next()) { s4=rs.getString("name"); s5=rs.getString("adminiclass"); }
String s6=null; String s7=null; rs=DBHelper.query("select* from studentgrade
where sid="+s2); while (rs.next()) { s6=rs.getString("classcode");
s7=rs.getString("subject"); } if(s6!=null||s7!=null){
JOptionPane.showMessageDialog(null, "该科目已存在成绩!"); }else{ //定义数据 String
studentgrade = studentgrade2.getText(); String classcode=classcode1.getText();
String sql = "insert into
studentgrade(sid,name,adminiclass,classcode,subject,studentgrade)
value("+s2+",'"+s4+"','"+s5+"','"+classcode+"','"+subject+"','"+studentgrade+"')";
DBHelper.update(sql); JOptionPane.showMessageDialog(null, "数据添加成功!"); } } catch
(Exception e11) { e11.printStackTrace(); } sid22.setText("");
subject2.setText(""); // 添加成功后 重置信息输入框 studentgrade2.setText("");
classcode1.setText(""); } table(DBHelper.query("select * from studentgrade
order by sid ")); // 初始面板显示信息 } }); back.addActionListener(this);
panel3.setVisible(true); add(panel3, "South"); back.addActionListener(new
ActionListener() { //返回选择功能界面 public void actionPerformed(ActionEvent e) {
table(DBHelper.query("select * from studentgrade order by sid ")); // 初始面板显示信息
remove(panel3); mainpanel(); } }); setVisible(true); } //删除框 private void
panel4() { table(DBHelper.query("select * from studentgrade order by sid "));
// 初始面板显示信息 remove(panel0); panel4 = new Panel(); // 设置 输入框
panel4.setLayout(new GridLayout(3,3)); sid2 = new Label("学生编号"); subject1 = new
Label("科目"); empty = new Label(""); empty1=new Label(""); delete=new
Button("删除"); reset = new Button("修改"); back=new Button("返回"); sid22 = new
TextField(); subject2 = new TextField(); panel4.add(sid2); panel4.add(sid22);
panel4.add(empty); panel4.add(subject1); panel4.add(subject2);
panel4.add(empty1); panel4.add(delete); panel4.add(back);
delete.addActionListener(this); back.addActionListener(this);
panel4.setVisible(true); add(panel4, "South"); back.addActionListener(new
ActionListener() { //返回选择功能界面 public void actionPerformed(ActionEvent e) {
table(DBHelper.query("select * from studentgrade order by sid ")); // 初始面板显示信息
remove(panel4); mainpanel(); } }); setVisible(true); } //按钮事件合集 public void
actionPerformed(ActionEvent e) { Object obj = e.getSource(); String
s4=null,s5=null; String s1=sid11.getText(); if (obj == look) { try { //
查询学号为"s1"的学生 rs = DBHelper.query("select * from studentgrade where sid='" + s1
+ "'"); int sid1 = 0; while (rs.next()) { String sa = rs.getString("sid"); if
(s1 != sa) { sid1 = 1; break; } } if (sid1== 0) { if (sid11.getText().length()
== 0) { // 当查询框为空时 提示 JOptionPane.showMessageDialog(null, "将查询所有学生信息");
table(DBHelper.query("select * from studentgrade order by sid ")); } else {
JOptionPane // 当输入学号不存在时 .showMessageDialog(null, "找不到学号为" + s1 + "的学生信息"); } }
else { rs = DBHelper .query("select * from studentgrade where sid='" + s1 +
"'"); table(rs); } } catch (SQLException e1) { // TODO 自动生成的 catch 块
e1.printStackTrace(); } } else if (obj == delete) { String s2 =sid22.getText();
String subject= subject2.getText();//底部 String sidd ; try { rs =
DBHelper.query("select * from studentgrade where sid='" +s2+ "'"); int sid1=0;
int sub1=0; while (rs.next()) { sidd=rs.getString("sid"); if (s2.equals( sidd))
{ sid1 = 1; break;//存在学号 } } DBHelper.close(); rs = DBHelper.query("select *
from studentgrade where sid='" +s2+ "'"); while (rs.next()) { String
subb=rs.getString("subject"); if(subject.equals(subb)){ //subject是自己输入框的科目
sub1=1; break; } } if (sid22.getText().length() ==
0||subject2.getText().length()==0) { // 当查询框为空时 提示
JOptionPane.showMessageDialog(null, "请输入学生编号与科目"); } else if (sid1== 0) {
JOptionPane.showMessageDialog(null, "找不到学号为" + s2 // + "的学生信息"); } else
if(sub1==0){ JOptionPane.showMessageDialog(null, "找不到该科目" ); } else { String
sql =" delete from studentgrade where subject='"+subject+"' and sid='"+s2+"'" ;
DBHelper.update(sql); JOptionPane .showMessageDialog(null, "您删除了学号为" + s2 +
",科目为"+subject+"的成绩"); // } } catch (Exception e2) { // TODO: handle exception
} table(DBHelper.query("select * from studentgrade order by sid ")); //
初始面板显示信息 sid22.setText(""); subject2.setText(""); } else if (obj == reset) {
String s2 =sid22.getText(); String subject= subject2.getText();//底部 try { rs =
DBHelper.query("select * from studentgrade where sid='" +s2+ "'"); int sid1=0;
int sub1=0; while (rs.next()) { String sidd =rs.getString("sid"); if
(s2.equals( sidd)) { sid1 = 1; break;//存在学号 } } DBHelper.close(); rs =
DBHelper.query("select * from studentgrade where sid='" +s2+ "'"); while
(rs.next()) { String subb=rs.getString("subject"); if(subject.equals(subb)){
//subject是自己输入框的科目 sub1=1; //存在 break; } } if (sid22.getText().length() ==
0||subject2.getText().length()==0||studentgrade2.getText().length()==0) { //
当查询框为空时 提示 JOptionPane.showMessageDialog(null, "请正确输入所有信息"); } else if (sid1 ==
0) { JOptionPane.showMessageDialog(null, "找不到学号为" + s2 // + "的学生信息"); } else if
(sub1==0 ) { JOptionPane.showMessageDialog(null, "找不到该科目"); }else{ String
studentgrade = studentgrade2.getText(); String sql = "update studentgrade set
studentgrade='"+studentgrade +"'where sid=" + s2+" and subject='"+subject+"' ";
DBHelper.update(sql); JOptionPane .showMessageDialog(null, "修改成功!"); rs =
DBHelper.query("select * from studentgrade where sid='"+s2+ "'"); } }catch
(Exception e1) { // TODO: handle exception } sid22.setText("");
subject2.setText(""); studentgrade2.setText(""); table(DBHelper.query("select *
from studentgrade order by sid ")); // 初始面板显示信息 } else if (obj == refresh) {
table(DBHelper.query("select * from studentgrade order by sid ")); setSize(450,
320);// 设置大小、可视化、退出 setVisible(true); } } private void table(ResultSet rs) { //
TODO 自动生成的方法存根 String[] cowname = { "学生编号", "名字", "行政班", "教学班", "科目", "成绩", };
if (model != null || jTable1 != null) remove(check); model = new
DefaultTableModel(); model.setColumnIdentifiers(cowname); try { while
(rs.next()) { Vector<String> data = new Vector<String>();
data.add(rs.getString("sid")); data.add(rs.getString("name"));
data.add(rs.getString("adminiclass")); data.add(rs.getString("classcode"));
data.add(rs.getString("subject")); data.add(rs.getString("studentgrade"));
model.addRow(data); } } catch (SQLException e1) { // TODO Auto-generated catch
block e1.printStackTrace(); } // 设置信息框 jTable1 = new JTable(model);
jTable1.setEnabled(false); check = new JScrollPane(jTable1); add(check,
"Center"); setVisible(true); } /* public static void main(String[] args) {
GradeChange Gender = new GradeChange(); }*/ }
<>部分截图

主面板
背景是我们学校的特色,华软丝木棉
学号会根据入学时间,系别专业,行政班级自动生成
点击下方不同的按键,会弹出对应的框

技术
下载桌面版
GitHub
Gitee
SourceForge
百度网盘(提取码:draw)
云服务器优惠
华为云优惠券
腾讯云优惠券
阿里云优惠券
Vultr优惠券
站点信息
问题反馈
邮箱:[email protected]
吐槽一下
QQ群:766591547
关注微信