学籍管理系统(内含源代码)
- 格式:doc
- 大小:4.03 MB
- 文档页数:33
C语言学生管理系统代码
简介
学生管理系统是一个用于管理学生信息的简单程序,它可以实现添加学生信息、显示学生信息、修改学生信息和删除学生信息等功能。
通过这个系统,学校或机构可以更方便地管理和维护学生的相关数据。
功能
1.添加学生信息:通过输入学生的姓名、学号、年龄和性别等信息,将
学生信息存储在系统中。
每个学生信息包括学号、姓名、年龄和性别等关键信息。
2.显示学生信息:可以显示系统中所有学生的信息,包括学号、姓名、
年龄和性别。
3.修改学生信息:通过输入学生的学号,可以修改该学生的姓名、年龄
和性别等信息。
4.删除学生信息:通过输入学生的学号,可以删除该学生的信息。
实现
下面是一个简单的C语言学生管理系统代码示例:
```c #include <stdio.h> #include <string.h>
#define MAX_STUDENTS 100
// 定义学生结构体 struct Student { int id; char name[100]; int age; char
gender[10]; };
// 定义全局变量,用于存储学生信息和统计学生数量 struct Student
students[MAX_STUDENTS]; int num_students = 0;
// 添加学生 void addStudent() { if (num_students >= MAX_STUDENTS) { printf(。
主要代码如下:1、登录界面代码:Dim cn As New ADODB.ConnectionDim rst As New ADODB。
RecordsetPrivate Sub Command1_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB。
RecordsetStatic i%cn。
ConnectionString = ”Provider=SQLOLEDB。
1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847”cn.Openusna = Trim(Text1.Text)mysql = "select * from 用户表 where 用户名='”& usna &”’”rst。
Open mysql, cnIf rst。
EOF ThenMsgBox ”用户名不存在!”cn。
CloseText1.Text = "”Text2.Text = ""Text1。
SetFocusElseIf Trim(rst(”密码”)) = Trim(Text2。
Text) Then管理界面.ShowElsei = i + 1If i < 3 ThenMsgBox ”用户名或密码错误!”, vbOKOnly + vbExclamation, "警告”cn。
CloseText2。
Text = ””Text1.Text = ””Text1。
SetFocusElseMsgBox "该用户已被锁定!”, vbOKOnly + vbExclamation, "警告"End IfEnd IfEnd IfEnd SubPrivate Sub Command2_Click()Text1。
#include<stdio.h>#include<string.h>#define N 10struct date_type{int year;int month;}date;struct stud_type{char academy[10];char class1[10];int num;char name[10];char sex[4];struct date_type date;char address[10];int score[3];float average;int sum;int jilu;};struct stud_type stu[N];void duru(struct stud_type stu[]); /*数据读入*/void Add(struct stud_type stu[]); /*增加学生*/void Delete(struct stud_type stu[]); /*删除学生*/void Modify(struct stud_type stu[]); /*修改学生*/void Search(struct stud_type stu[]); /*查询学生*/void Print(struct stud_type stu[]); /*输出所有学生信息*/void Stat(struct stud_type stu[]); /*统计*/void Save(struct stud_type stu[]); /*数据存盘*/int r=0;void main(){int x;duru(stu);do{printf("※※※※※※※※※※※※※※※※※※※※※※※※\n");printf("※欢迎使用本软件※\n");printf("※~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~※\n");printf("※指导老师:张老师※\n");printf("※※\n");printf("※制作者:黄同学※\n");printf("※※\n");printf("※※※※※※※※※※※※※※※※※※※※※※※※\n");printf("**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~** \n");printf("******************学籍管理系统******************\n");printf("** **\n");printf("** 1.录入学生信息**\n");printf("****\n");printf("********* 2.修改学生信息*********\n");printf("****\n");printf("**** 3.查询学生信息****\n");printf("****\n");printf("************* 4.浏览所有学生信息**********\n");printf("****\n");printf("**** 5.删除学生信息****\n");printf("** **\n");printf("********* 6.综合统计*********\n");printf("** **\n");printf("**0.保存并退出系统**\n");printf("****\n");printf("**********************************************\n");printf("**----------------------------------------------- -----------------***\n");printf("请在0-6中选择: ");scanf("%d",&x);switch(x){case 1:Add(stu); /*录入模块*/break;case 2:Modify(stu); /*修改模块*/break;case 3:Search(stu); /*查询模块*/break;case 4:Print(stu); /*输出模块*/break;case 5:Delete(stu); /*删除模块*/break;case 6:Stat(stu); /*统计模块*/break;case 0:Save(stu);break;}}while(x!=0);}void Add (struct stud_type stu[]) /*录入模块*/{int i;char k;for(i=r;i<N;i++){printf("\n 请输入学院:");scanf("%s",stu[i].academy);printf("\n 请输入班级:");scanf("%s",stu[i].class1);printf("\n 请输入学号:");scanf("%d",&stu[i].num);printf("\n 请输入姓名:");scanf("%s",stu[i].name);printf("\n 请输入性别:");scanf("%s",stu[i].sex);printf("\n请输入出生年月:");scanf("%d%d",&stu[i].date.year,&stu[i].date.month);printf("\n 请输入地址:");scanf("%s",stu[i].address);printf("\n 请输入成绩:");scanf("%d%d%d",&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);r=r+1;stu[i].sum=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];stu[i].average=stu[i].sum/3.0;printf("----------是否继续??(y/n):");scanf("%s",&k);if(k=='y'||k=='Y') continue;elseprintf("**********录入结束!**********\n\n");return;}}void Save(struct stud_type stu[]) /*保存模块*/{FILE *fp1; /*指向文件的指针*/int i;stu[0].jilu=r;if((fp1=fopen("E:\\xj.txt","wb"))==NULL) /*打开文件,并判断打开是否正常*/{printf("**********打开文件失败!**********\n\n");return;printf("开始存盘!\n");for(i=0;i<r;i++)if(fwrite(&stu[i],sizeof(struct stud_type),1,fp1)==0)printf("**********数据存盘失败!**********\n\n");fclose(fp1);printf("**********存盘成功!**********\n"); /*显示保存成功*/}void Search(struct stud_type stu[]) /*查询模块*/{int y=0,i,k;printf("请输入学号:");scanf("%d",&k);for(i=0;i<r;i++){if(k==stu[i].num){printf("学院:%s\n班级:%s\n学号:%d\n姓名:%s\n性别:%s\n出生年月:%d%d\n地址:%s\n 成绩:\nC语言:%d高数:%d英语:%d\n",stu[i].academy,stu[i].class1,stu[i].num,stu[i].name,stu[i].sex,stu[i].date.year,stu[i].date. month,stu[i].address,stu[i].score[0],stu[i].score[1],stu[i].score[2]);y=1;}}if(y==0)printf("**********查无此人!**********\n\n");return;}void Delete(struct stud_type stu[]) /*删除模块*/{int i,j,k,y=0;int m=16899168,n;printf("请输入密码:");scanf("%d",&n);if(n==m);else{printf("**********密码错误!**********\n\n");return;}printf("请输入学号:");scanf("%d",&k);for(i=0;i<r;i++){if(k==stu[i].num)for(j=i;j<r;j++)stu[j]=stu[j+1];r=r-1;printf("**********删除成功!**********\n\n");y=1;}}if(y==0)printf("**********查无此人!**********\n\n");}void Print(struct stud_type stu[]) /*输出模块*/ {int i,j,k,n;struct stud_type t;printf(" 1.按学号排序,2.按总分排序(由高到低)\n");printf("\n请在1和2中选择:");scanf("%d",&n);if(n==1) /*选择排序*/ for(i=0;i<r-1;i++){k=i;for(j=i+1;j<r;j++)if(stu[k].num>stu[j].num)k=j;if(k!=i){t=stu[i];stu[i]=stu[k];stu[k]=t;}}if(n==2)for(i=0;i<r-1;i++){k=i;for(j=i+1;j<r;j++)if(stu[k].sum<stu[j].sum)k=j;if(k!=i){t=stu[i];stu[i]=stu[k];stu[k]=t;}for(i=0;i<r;i++){printf("\n学院\t班级\t学号\t姓名\t性别\t出生年月\t地址\n");printf("%s\t%s\t%d\t%s\t%s\t%d %d\t\t%s\n",stu[i].academy,stu[i].class1,stu[i].num,stu[i].name,s tu[i].sex,stu[i].date.year,stu[i].date.month,stu[i].address);printf("C语言\t高数\t英语\t平均分\t总分\n");printf("%d\t%d\t%d\t%0.1f\t%d\n",stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].average,stu[i ].sum);}}void Stat(struct stud_type stu[]) /*统计模块*/{int i,j,k;printf("0.C语言1.高数2.英语");printf("请在0-2中选择:");scanf("%d",&j);k=j;printf("90-100:\n");printf(" 学号\t姓名\t成绩\n");for(i=0;i<r;i++){if(stu[i].score[k]>=90)printf(" %d\t%s\t%d\n",stu[i].num,stu[i].name,stu[i].score[k]);}printf("80-90:\n");printf(" 学号\t姓名\t成绩\n");for(i=0;i<r;i++){if(stu[i].score[k]<90&&stu[i].score[k]>=80)printf(" %d\t%s\t%d\n",stu[i].num,stu[i].name,stu[i].score[k]);}printf("70-80:\n");printf(" 学号\t姓名\t成绩\n");for(i=0;i<r;i++){if(stu[i].score[k]<80&&stu[i].score[k]>=70)printf(" %d\t%s\t%d\n",stu[i].num,stu[i].name,stu[i].score[k]);}printf("60-70:\n");printf(" 学号\t姓名\t成绩\n");for(i=0;i<r;i++){if(stu[i].score[k]<70&&stu[i].score[k]>=60)printf(" %d\t%s\t%d\n",stu[i].num,stu[i].name,stu[i].score[k]);}printf("60分以下:\n");printf(" 学号\t姓名\t成绩\n");for(i=0;i<r;i++){if(stu[i].score[k]<60)printf(" %d\t%s\t%d\n",stu[i].num,stu[i].name,stu[i].score[k]);}}void Modify(struct stud_type stu[]) /*修改模块*/{int k,i,y=0;int m=16899168,n;printf("请输入密码:");scanf("%d",&n);if(n==m);else{printf("**********密码错误!**********\n\n");return;}printf("************修改学生信息************\n");printf("\n请输入要修改学生的学号: ");scanf("%d",&k);for(i=0;i<r;i++){if(k==stu[i].num){printf("\n请输入新内容:\n");printf("\n 请输入学院:");scanf("%s",stu[i].academy);printf("\n 请输入班级:");scanf("%s",stu[i].class1);printf("\n 请输入学号:");scanf("%d",&stu[i].num);printf("\n 请输入姓名:");scanf("%s",stu[i].name);printf("\n 请输入性别:");scanf("%s",stu[i].sex);printf("\n请输入出生年月:");scanf("%d%d",&stu[i].date.year,&stu[i].date.month);printf("\n 请输入地址:");scanf("%s",stu[i].address);printf("\n 请输入成绩:");scanf("%d%d%d",&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);printf("\n**********修改成功!**********\n\n");y=1;}}if(y==0)printf("**********查无此人!**********\n\n");return;}void duru(struct stud_type stu[]) /*数据读入模块*/{int i;FILE *fp; /*指向文件的指针*/if((fp=fopen("E:\\xj.txt","rb"))==NULL) /*打开文件,并判断打开是否正常*/{printf("打开文件失败!\n");return;}printf("文件开始读取!\n");rewind(fp);for(i=0;i<=r;i++){fread(&stu[i],sizeof(struct stud_type),1,fp);r=stu[0].jilu;}printf("\n文件成功读取!\n");fclose(fp);r=stu[0].jilu;}。
c语言学籍管理系统源代码学籍管理系统的背景及意义随着社会的不断发展和教育的普及,学籍管理工作日益被重视。
传统的手工管理学籍的方式效率低下,存在着各种弊端,以致无法满足现代学校管理的需求。
因此,开发一款高效、便捷、可靠的学籍管理系统成为普遍需求,为了提高管理效率、减少工作难度,学籍管理系统被越来越广泛地使用。
本文将介绍一款基于C语言开发的学籍管理系统的源代码。
基本功能该学籍管理系统可以实现学生信息的录入、删除、修改和查询,以及学生的成绩录入、修改和查询。
此外,该系统还具备数据存储和文件读写的功能,能够自动保存学生信息和成绩数据,保障数据的安全性和可靠性。
模块设计该系统按照功能模块划分,主要分为三个模块:学生信息管理模块、学生成绩管理模块和数据存储与文件读写模块。
学生信息管理模块该模块主要实现学生信息的录入、删除、修改和查询等基本功能。
以下为该模块的主要源代码:```struct student {char name[20]; // 姓名int id; // 学号char sex[5]; // 性别char major[20]; // 专业};struct student stu[1000]; // 学生信息结构体数组int num_of_stu = 0; // 学生总数void add_student() { // 添加学生信息printf("请输入学生姓名:");scanf("%s", stu[num_of_stu].name);printf("请输入学生学号:");scanf("%d", &stu[num_of_stu].id);printf("请输入学生性别:");scanf("%s", stu[num_of_stu].sex);printf("请输入学生专业:");scanf("%s", stu[num_of_stu].major);num_of_stu++;printf("添加成功!\n");}void delete_student() { // 删除学生信息int delete_id;printf("请输入要删除的学生学号:");scanf("%d", &delete_id);int index = search_student_by_id(delete_id); if (index == -1) {printf("该学号不存在!\n");return;}for (int i = index; i < num_of_stu - 1; i++) { stu[i] = stu[i + 1];}num_of_stu--;printf("删除成功!\n");}void modify_student() { // 修改学生信息int modify_id;printf("请输入要修改的学生学号:");scanf("%d", &modify_id);int index = search_student_by_id(modify_id); if (index == -1) {printf("该学号不存在!\n");return;}printf("请输入学生姓名:");scanf("%s", stu[index].name);printf("请输入学生学号:");scanf("%d", &stu[index].id);printf("请输入学生性别:");scanf("%s", stu[index].sex);printf("请输入学生专业:");scanf("%s", stu[index].major);printf("修改成功!\n");}int search_student_by_id(int id) { // 根据学号查询学生信息for (int i = 0; i < num_of_stu; i++) {if (stu[i].id == id) {return i;}}return -1;}void query_student() { // 查询学生信息int query_id;printf("请输入要查询的学生学号:");scanf("%d", &query_id);int index = search_student_by_id(query_id);if (index == -1) {printf("该学号不存在!\n");return;}printf("姓名\t学号\t性别\t专业\n");printf("%s\t%d\t%s\t%s\n", stu[index].name,stu[index].id, stu[index].sex, stu[index].major);}```学生成绩管理模块该模块主要实现学生成绩信息的录入、修改和查询等功能。
c语言学生管理系统源代码#include <stdio.h>。
#include <stdlib.h>。
#include <string.h>。
/*定义学生结构体*/。
typedef struct student。
char num[20]; //学号。
char name[20]; //姓名。
int c; //语文成绩。
int math; //数学成绩。
float ave; //平均分。
struct student *next;。
} stu;。
/*函数声明*/。
void menu_select(); //显示菜单。
void add(); //添加学生信息。
void delete(); //删除学生信息。
void modify(); //修改学生信息。
void search(); //查询学生信息。
void get_ave(); //计算学生平均成绩。
void display(); //显示学生信息。
void esc(); //退出系统。
int main()。
menu_select();。
return 0;。
}。
//显示菜单。
void menu_select()。
int select;。
while (1)。
printf("\n学生管理系统\n");。
printf("------菜单------\n");。
printf("1.添加学生信息 2.删除学生信息\n");。
printf("3.修改学生信息 4.查询学生信息\n");。
printf("5.计算学生平均成绩 6.显示学生信息\n");。
printf("7.退出系统\n");。
printf("请输入您的选择:");。
scanf("%d", &select);。
数据库所用的数据自己导入MYSQL5.5,Navicat8就可以用了。
下面是具体的数据资料/*MySQL Data TransferSource Host: localhostSource Database: simsTarget Host: localhostTarget Database: simsDate: 2013-6-25 9:24:26*/SET FOREIGN_KEY_CHECKS=0;-- ------------------------------ Table structure for manager-- ----------------------------DROP TABLE IF EXISTS `manager`;CREATE TABLE `manager` (`id` varchar(10) NOT NULL,`name` varchar(30) NOT NULL,`Mima` varchar(20) NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;-- ------------------------------ Table structure for studentinfo-- ----------------------------DROP TABLE IF EXISTS `studentinfo`;CREATE TABLE `studentinfo` (`Sname` varchar(30) NOT NULL,`Ssex` varchar(10) NOTNULL,`Snumber` varchar(10) NOT NULL,`Sprofession` varchar(30) NOT NULL,`Sclass`varchar(20) NOT NULL,`Sdate` varchar(30) character set utf8 collate utf8_unicode_ciNOT NULL,PRIMARY KEY (`Snumber`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='InnoDBfree: 4096 kB';-- ------------------------------ Table structure for userinfo-- ----------------------------DROP TABLE IF EXISTS `userinfo`;CREATE TABLE `userinfo` (`id` varchar(10) NOT NULL,`name` varchar(30) NOT NULL,`Mima` varchar(20) character set utf8 collate utf8_unicode_ci NOT NULL, PRIMARY KEY(`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;-- ------------------------------ Records-- ----------------------------INSERT INTO `manager` VALUES ('1', '1', '2');INSERT INTO `manager` VALUES ('2', '恩恩', '123456');INSERT INTO `manager` VALUES ('3', '大大', '123456');INSERT INTO `manager` VALUES ('4', '啊啊', '123456');INSERT INTO `manager` VALUES ('5', '5', '5');INSERT INTO `manager` VALUES ('6', '孙霞', '123456');INSERT INTO `studentinfo` V ALUES ('张三', '男', '2010303755', '数学', '2', '2010-02- 12');INSERT INTO `studentinfo` V ALUES ('李四', '男', '2010303760', '物理', '1', '1995.9.6'); INSERT INTO `studentinfo` V ALUES ('王二', '女', '2010303761', '应数', '2','1990.9.11');INSERT INTO `studentinfo` V ALUES ('麻子', '女', '2010303762', '信计', '1','1999.9.10');INSERT INTO `userinfo` V ALUES ('1', '1', '1');INSERT INTO `userinfo` V ALUES ('13', '13', '1');INSERT INTO `userinfo` V ALUES ('2', '2', '2');INSERT INTO `userinfo` V ALUES ('3', '3', '3');INSERT INTO `userinfo` V ALUES ('6', '6', '6');INSERT INTO `userinfo` V ALUES ('7', '7', '6');下面是相应的程序:package MS;import java.awt.event.ActionEvent;import java.awt.event.ActionListener; import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.GridLayout;import java.awt.Toolkit;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.SwingConstants;public class Add implements ActionListener {JFrame f1;Container ct;JPanel jp,jp1,jp2,jp3;JButton btn1,btn2;JLabel label;JTextField tf1,tf2,tf3,tf4,tf5,tf6;Add(){f1=new JFrame();ct=f1.getContentPane();//初始化面板jp=new JPanel();jp1=new JPanel(new GridLayout(6,1));jp2=new JPanel(new GridLayout(6,1));jp3=new JPanel();btn1=new JButton("确定");btn2=new JButton("取消");label=new JLabel("<html><font color=#CC00FF size='4'>添加学生信息</font>",SwingConstants.CENTER);label.setForeground(Color.gray);tf1=new JTextField(20);tf2=new JTextField(20);tf3=new JTextField(20);tf4=new JTextField(20);tf5=new JTextField(20);tf6=new JTextField(20);tf6.setText("例:2000-02-02");//文本框加入提示语tf6.addFocusListener(new FocusListener(){public void focusGained(FocusEvent e) {tf6.setText("");}public void focusLost(FocusEvent e) {}});jp.add(label);ct.add(jp,"North");jp1.add(new JLabel("姓名",SwingConstants.CENTER));jp2.add(tf1);jp1.add(new JLabel("性别",SwingConstants.CENTER));jp2.add(tf2);jp1.add(new JLabel("学号",SwingConstants.CENTER));jp2.add(tf3);jp1.add(new JLabel("专业",SwingConstants.CENTER));jp2.add(tf4);jp1.add(new JLabel("班级",SwingConstants.CENTER));jp2.add(tf5);jp1.add(new JLabel("入学时间",SwingConstants.CENTER));jp2.add(tf6);jp3.add(btn1);jp3.add(btn2);ct.add(jp1,"West");ct.add(jp2,"East");ct.add(jp3,"South");Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width;int y=screen.height;f1.setSize(350,330);int xcenter=(x-350)/2;int ycenter=(y-330)/2;f1.setLocation(xcenter, ycenter);f1.setVisible(true);//f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);btn1.addActionListener(this);btn2.addActionListener(this);}public void insert(){if(tf1.getText().equals("")||tf2.getText().equals("")||tf3.getText().equals("")||tf4.getText().equals("")||tf5.getText().equals("")||tf6.getText().equals("")){JOptionPane.showMessageDialog(f1,"请填写完整信息");return;}try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connectioncon=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String s="insert into studentinfo values('"+tf1.getText()+"','"+tf2.getText()+"','"+tf3.getText()+"','"+tf4.getText()+"','"+tf5.getText()+"','"+tf6.getText()+"');";String query="select * from studentinfo where Snumber='"+tf3.getText().trim()+"'";ResultSet res=st.executeQuery(query);if(res.next()){JOptionPane.showMessageDialog(f1,"学号信息已经存在!");con.close();tf3.setText("");}else if(tf6.getText().length()!=10){JOptionPane.showMessageDialog(f1,"入学时间格式有误!");con.close();tf6.setText("");}int insert=st.executeUpdate(s);if(insert==1){JOptionPane.showMessageDialog(f1,"录入信息成功!");tf1.setText("");tf2.setText("");tf3.setText("");tf4.setText("");tf5.setText("");tf6.setText("");}}catch(SQLException e){System.out.println("错误代码:"+e.getErrorCode());System.out.println("错误信息:"+e.getMessage());}}@SuppressWarnings("deprecation")public void actionPerformed(ActionEvent e){String cmd=e.getActionCommand();if(cmd.equals("确定")){insert();}else if(cmd.equals("取消")){f1.hide();}}public Container getCt(){return ct;}public void setCt(Container ct){this.ct = ct;}}package MS;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.SwingConstants;public class Delete implements ActionListener {JFrame f2;Container ct;JPanel jp1,jp2,jp3,jp4;JLabel label;JTextField text;JTable table;//接收数据库中返回的信息JButton btn1,btn2,btn3;Object columnName[]={"姓名","性别","学号","专业","班级","入学时间"};Object ar[][]=new Object[80][6];Delete(){f2=new JFrame();ct=f2.getContentPane();jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();jp4=new JPanel();label=new JLabel();text=new JTextField();btn1=new JButton("查询");btn2=new JButton("删除");btn3=new JButton("取消");label=new JLabel("<html><font color=#CC00FF size='4'>请输入要删除的学生姓名:</font>",SwingConstants.CENTER);label.setBackground(Color.blue);table=new JTable(ar,columnName);JScrollPane scroll=new JScrollPane(table);text=new JTextField(20);jp2.add(btn1);jp2.add(btn2);jp2.add(btn3);jp1.add(label);jp1.add(text);ct.add(jp1,"North");jp3.setLayout(new BorderLayout());jp3.add(new JLabel("学生信息如下"));jp3.add(scroll);ct.add(jp2,"South");ct.add(jp3,"Center");Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width;int y=screen.height;f2.setSize(450, 400);int xcenter=(x-450)/2;int ycenter=(y-400)/2;f2.setLocation(xcenter, ycenter);f2.setVisible(true);//f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);btn1.addActionListener(this);btn2.addActionListener(this);btn3.addActionListener(this);}int i=0;public void show(String s){while(i>=0){ar[i][0]="";ar[i][1]="";ar[i][2]="";ar[i][3]="";ar[i][4]="";ar[i][5]="";i--;}i=0;try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connection con=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String sql="select * from studentinfo where Sname='"+s+"'";ResultSet res=st.executeQuery(sql);/*if(!(res.next())){JOptionPane.showMessageDialog(f,"所要查询的信息不存在");} */while(res.next()){String sName=res.getString(1);String sSex=res.getString(2);String sNumber=res.getString(3);String sProfession=res.getString(4);String sClass=res.getString(5);String sDate=res.getString(6);ar[i][0]=sName;ar[i][1]=sSex;ar[i][2]=sNumber;ar[i][3]=sProfession;ar[i][4]=sClass;ar[i][5]=sDate;i++;}f2.repaint();con.close();}catch(SQLException e){System.out.println("错误代码:"+e.getErrorCode());System.out.println("错误信息:"+e.getMessage());}}public void delete(int line){try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connection con=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String name=(String)(ar[line][2]);String sql="delete from studentinfo where Snumber ='"+name+"'";int del=st.executeUpdate(sql);if(del==1){ar[line][0]="";ar[line][1]="";ar[line][2]="";ar[line][3]="";ar[line][4]="";ar[line][5]="";JOptionPane.showMessageDialog(null,"删除成功!","信息", JOptionPane.YES_NO_OPTION);}con.close();f2.repaint();}catch(SQLException e){System.out.println("错误代码:"+e.getErrorCode());System.out.println("错误信息:"+e.getMessage());}}@SuppressWarnings("deprecation")public void actionPerformed(ActionEvent e){String cmd=e.getActionCommand();if(cmd.equals("查询")){String qu=text.getText().trim();show(qu);}if(cmd.equals("删除")){int de=table.getSelectedRow();if(de==-1){JOptionPane.showMessageDialog(null,"请选定要删除的行","错误信息", JOptionPane.YES_NO_OPTION);}else{delete(de);}}if(cmd.equals("取消")){f2.hide();}}}package MS;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.SwingConstants;public class Liulan implements ActionListener {JFrame f4;Container ct;JPanel jp1,jp2,jp3,jp4;JLabel label;JButton btn1,btn2;JTable table;Object[][] ar=new Object[80][6];Object[] columnName={"姓名","性别","学号","专业","班级","入学时间"};Liulan(){f4=new JFrame();ct=f4.getContentPane();jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();jp4=new JPanel();btn1=new JButton("点击浏览");btn2=new JButton(" 取消");label=new JLabel("<html><font color=#00FF22 size='4'>学生信息浏览<font>",SwingConstants.CENTER);label.setBackground(Color.blue);table=new JTable(ar, columnName);JScrollPane scroll=new JScrollPane(table);jp1.add(label);jp2.add(btn1);jp2.add(btn2);jp3.add(scroll);ct.add(jp1,"North");ct.add(jp3,"Center");ct.add(jp2,"South");Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width;int y=screen.height;f4.setSize(500,530);int xcen=(x-500)/2;int ycen=(y-530)/2;f4.setLocation(xcen,ycen);f4.setVisible(true);btn1.addActionListener(this);btn2.addActionListener(this);}int i=0;public void select(){while(i>=0){ar[i][0]="";ar[i][1]="";ar[i][2]="";ar[i][3]="";ar[i][4]="";ar[i][5]="";i--;}i=0;try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connection con=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String s="select * from studentinfo";ResultSet res=st.executeQuery(s);while(res.next()){String sName=res.getString(1);String sSex=res.getString(2);String sNumber=res.getString(3);String sProfession=res.getString(4);String sClass=res.getString(5);String sDate=res.getString(6);ar[i][0]=sName;ar[i][1]=sSex;ar[i][2]=sNumber;ar[i][3]=sProfession;ar[i][4]=sClass;ar[i][5]=sDate;i++;}f4.repaint();con.close();}catch(SQLException e){System.out.println("错误代码:"+e.getErrorCode());System.out.println("错误信息:"+e.getMessage());}}@SuppressWarnings("deprecation")public void actionPerformed(ActionEvent e){// TODO Auto-generated method stubString cmd=e.getActionCommand();if(cmd.equals("点击浏览")){select();}else if(cmd.equals(" 取消")){f4.hide();}}}package MS;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.sql.Connection;import java.sql.DriverManager;import javax.swing.ButtonGroup;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.JRadioButton;import javax.swing.JTextField;import javax.swing.SwingConstants;@SuppressWarnings("serial")public class Login extends JFrame implements ActionListener {Container cp=null;JFrame f=null;JButton button1,button2,button3;JTextField t1;JPasswordField t2;JLabel jlable1,jlable2;JRadioButton rabtn1,rabtn2;Color c;JPanel jp1,jp2,jp3;String table=null;Login(){f=new JFrame("学生信息管理系统");button1=new JButton("确定");button2=new JButton("取消");button3=new JButton("注册");//button3.setOpaque(false);button3.setBorder(null);button3.setBackground(Color.getColor("#292421"));rabtn1=new JRadioButton("普通用户");rabtn1.setBackground(Color.getColor("#292421"));rabtn2=new JRadioButton("管理员");rabtn2.setBackground(Color.getColor("#292421"));ButtonGroup group=new ButtonGroup();group.add(rabtn1);group.add(rabtn2);cp=f.getContentPane();jlable1=new JLabel("输入用户号");jlable2=new JLabel("输入密码");jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();t1=new JTextField(20);t2=new JPasswordField(20);//jp3.add(group);jp1.add(jlable1);jp1.add(t1);jp1.add(jlable2);jp1.add(t2);jp1.add(rabtn1);jp1.add(rabtn2);jp1.add(button3);JLabel JL=new JLabel("<html><font color=#292421 size='7'><i>欢迎登陆" + "</i></font>",SwingConstants.CENTER);cp.add(JL,"North");jp2.add(button1);jp2.add(button2);cp.add(jp1,"Center");cp.add("South",jp2);cp.setBackground(new Color(127, 255, 212 ));jp2.setBackground(new Color(127, 255, 212 ));jp1.setBackground(new Color(127, 255, 212 ));Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width;int y=screen.height;f.setSize(250,300);int xcenter=(x-300)/2;int ycenter=(y-300)/2;f.setLocation(xcenter,ycenter);/*显示在窗口中央*/f.setVisible(true);//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//------------------------------------------------------------///*监听事件*/button1.addActionListener(this);button2.addActionListener(this);button3.addActionListener(this);rabtn1.addItemListener(new ItemListener(){public void itemStateChanged(ItemEvent e){JRadioButton jop=(JRadioButton) e.getSource();if (jop.isSelected())table="userinfo";}});rabtn2.addItemListener(new ItemListener(){public void itemStateChanged(ItemEvent e){JRadioButton jop=(JRadioButton) e.getSource();if (jop.isSelected())table="manager";}});f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});}@SuppressWarnings("deprecation")public void confirm(String tableName){try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connection con=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String id=t1.getText().trim();String Mima=t2.getText().trim();String queryMima="select * from "+tableName+" where id='"+id+"' and mima='"+Mima+"'";ResultSet res=st.executeQuery(queryMima);if(res.next()){if(tableName.equals("manager"))new Mstudent(id);else if(tableName.equals("userinfo"))new Ustudent(id);f.hide();con.close();}else{JOptionPane.showMessageDialog(null,"密码错误请重输!!!","提示!",JOptionPane.YES_NO_OPTION);}t1.setText("");t2.setText("");}catch(SQLException g){System.out.println("错误代码:"+g.getErrorCode());System.out.println("错误内容:"+g.getMessage());}}ItemListener listen=new ItemListener(){public void itemStateChanged(ItemEvent e) {// TODO Auto-generated method stub}};public void actionPerformed(ActionEvent e){String cmd=e.getActionCommand();if(cmd.equals("确定")){if(table==null){JOptionPane.showMessageDialog(f,"请选择用户类型");}confirm(table);}else if(cmd.equals("取消")){f.dispose();}else if(cmd.equals("注册")){new Regist();}}public static void main(String []arg){new Login();}}package MS;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenuBar;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.SwingConstants;import javax.swing.border.TitledBorder;@SuppressWarnings("serial")public class Mstudent extends JFrame implements ActionListener {JButton Query = new JButton("查询信息");JButton add = new JButton("添加信息");JButton delete = new JButton("删除信息");JButton xiugai = new JButton("浏览全部信息");JButton liulan = new JButton("修改密码");JMenuBar mb = new JMenuBar();// 菜单栏JPanel jp = new JPanel();Container cp = getContentPane();String userName;Mstudent(){}Mstudent(String userName){erName = userName;mb.add(Query);mb.add(add);mb.add(delete);mb.add(xiugai);mb.add(liulan);JPanel j=new JPanel();j.add(mb,"Center");cp.add(j, "North");// 设置边框jp.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.blue, 2), null, TitledBorder.CENTER,TitledBorder.TOP));jp.setLayout(new BorderLayout());JLabel label1 = new JLabel("欢迎使用学生信息管理系统",SwingConstants.CENTER);jp.add(label1);JScrollPane scrollpane = new JScrollPane(jp);cp.add(scrollpane,"Center");setTitle("欢迎登陆" + "--" + "你好:" + userName);Toolkit kit = Toolkit.getDefaultToolkit();Dimension screen = kit.getScreenSize();int x = screen.width; /* 取得显示器窗口的宽度*/int y = screen.height; /* 取得显示器窗口的高度*/setSize(600, 600);int xcenter = (x - 600) / 2;int ycenter = (y - 600) / 2;setLocation(xcenter, ycenter);/* 显示在窗口中央*/setVisible(true);//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 注册临听器Query.addActionListener(this);add.addActionListener(this);delete.addActionListener(this);xiugai.addActionListener(this);liulan.addActionListener(this);}public void actionPerformed(ActionEvent e){String cmd = e.getActionCommand();if (cmd.equals("查询信息")){new QueryWays();}if (cmd.equals("添加信息")){new Add();}if (cmd.equals("删除信息")){new Delete();}if (cmd.equals("浏览全部信息")){new Liulan();}if (cmd.equals("修改密码")){new UpdateCode();}}public static void main(String[] args){new Mstudent("");}}package MS;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.GridLayout;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.SwingConstants;public class Query implements ActionListener {String sql =null;int a;String info;JFrame f3;// Container cp;JPanel jp1,jp2,jp3,jp4,jp,jpwest;JButton btn1,btn2;//确定,取消JLabel label,label2;//标签,请输入姓名(label)JTextField tf,tf1,tf2,tf3,tf4,tf5,tf6;//文本框Query(int a){this.a=a;f3=new JFrame();Container cp=f3.getContentPane();//初始化面板,按钮,标签,文本框jp=new JPanel();jp1=new JPanel();jp2=new JPanel(new GridLayout(6,1));jp3=new JPanel();jp4=new JPanel(new GridLayout(6,1));jpwest=new JPanel();btn1=new JButton("确定");btn2=new JButton("取消");label=new JLabel("<html><font color=#CC00FF size='4'>请输入姓名:" + "</font>",SwingConstants.CENTER);label2=new JLabel("<html><font color=#CC00FF size='4'>请输入学号:" + "</font>",SwingConstants.CENTER);label.setForeground(Color.gray);tf=new JTextField(20);//------------------------------------------------tf1=new JTextField(20);tf2=new JTextField(20);tf3=new JTextField(20);tf4=new JTextField(20);tf5=new JTextField(20);tf6=new JTextField(20);//布局,添加控件if(a==0){jp.add(label);jp.add(tf);}else if(a==1){jp.add(label2);jp.add(tf);}cp.add(jp,"North");jp4.add(new JLabel("姓名",SwingConstants.CENTER));jp2.add(tf1);jp4.add(new JLabel("性别",SwingConstants.CENTER));jp2.add(tf2);jp4.add(new JLabel("学号",SwingConstants.CENTER));jp2.add(tf3);jp4.add(new JLabel("专业",SwingConstants.CENTER));jp2.add(tf4);jp4.add(new JLabel("班级",SwingConstants.CENTER));jp2.add(tf5);jp4.add(new JLabel("入学时间",SwingConstants.CENTER));jp2.add(tf6);jp3.add(btn1);jp3.add(btn2);cp.add(jp4,"West");cp.add(jp2,"East");cp.add(jp3,"South");cp.add(jp1);Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width; //显示窗口宽度int y=screen.height;//窗口高度f3.setSize(350,330);int xcenter=(x-350)/2;int ycenter=(y-330)/2;f3.setLocation(xcenter,ycenter);f3.setVisible(true);//f3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);btn1.addActionListener(this);btn2.addActionListener(this);/*f3.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});*/。
学籍管理系统一、系统简介设计一个基于结构体数组的学生学籍管理系统,能实现对学生学籍信息进行录入,修改,删除,查询和输出等基本操作二、需求分析学籍管理系统应该实现以下功能:1、能录入学生的基本信息,包括学号,姓名,专业,年级,性别和出生日期信息,保存到结构体数组中。
2、能根据输入的学号查询学生,进行信息的修改。
3、能根据输入的学号从结构体数组中删除学生的记录。
4、实现查询功能,能根据输入的学号或年级在屏幕上显示相应的学生信息。
5、能在屏幕上以列表的方式输出所有学生的信息。
三、概要设计1、系统功能根据项目的开发要求,本系统划分成六个主要功能模块:录入学生信息模块、修改学生信息模块、删除学生信息模块、查询学生信息模块、输出模块和推出模块。
系统功能机构图如下:2、重要数据的数据结构设计学生学籍的记录项用结构体Stu message表示,包括6个属性,stuno,name、spec、grade、sex、birthday 分另U代表学生的学号、专业、年级、性另U和出生日期,其中birthday 类型为自定义的结构体类型Date.Struct stumessage {Char stuno[11]: // 学号Char name[9]: // 姓名Char spec[2]: // 专业Char grade: // 年级Char sex : // 性别Stuct date birthday: // 出生日期};日期类型date包括三个属性,分别代表年、月、日Struct date{int year : // 年Int month: //Int day: // H};3、函数设计学籍管理系统程序采用了结构化程序设计的思想,由1个.h 头文件和3个C源文件组成。
程序中除了主函数外,共设计了以下14个函数,分别包含在3个.c源文件中。
以下是这些函数原型及功能设计。
(1) void sysinfo(void)函数功能:在屏幕上输入系统及信息并等待用户响应。
-----------------------创建课程表-------------------create table C (课程号varchar(5) not null,课程名varchar(10) null,先行课smallint null,学分int null,备注varchar(16) null,constraint PK_C primary key (课程号))go-----------------------创建院系表-------------------create table Department (院系代号varchar(5) not null,院系名varchar(10) null,系主任varchar(8) null,备注varchar(16) null,constraint PK_DEPARTMENT primary key (院系代号))go-----------------------创建专业表-------------------create table Major (专业号varchar(5) not null,院系代号varchar(5) null,专业名称varchar(16) null,备注varchar(16) null,constraint PK_MAJOR primary key (专业号))go-----------------------在专业表上创建索引------------------- create index DM_FK on Major (院系代号ASC)go-----------------------创建学生与课程的成绩表---------------------- create table SC (学号bigint not null,课程号varchar(5) not null,成绩bigint null,constraint PK_SC primary key (学号, 课程号))go-----------------------在SC表上创建索引SC_FK与SC2_FK------------------- create index SC_FK on SC (学号ASC)Gocreate index SC2_FK on SC (课程号ASC)go-----------------------创建学生基本信息表-------------------create table S (班级varchar(16) null,学号bigint not null,院系代号varchar(5) null,专业号varchar(5) null,姓名varchar(6) null,性别varchar(2) null,出生年月datetime null,籍贯varchar(8) null,民族varchar(2) null,家庭住址varchar(20) null,入学时间datetime null,政治面貌varchar(6) null,身份证号char(18) null,联系电话varchar(12) null,备注varchar(14) null,constraint PK_S primary key (学号))go---------------------------创建院系代号索引------------------------------ create index SD_FK on S (院系代号ASC)go--------------------------创建专业号索引------------------------------ create index SM_FK on S (专业号ASC)go---------------------------创建教师与课程关系表------------------------------课程号varchar(5) not null,教师号varchar(5) not null,constraint PK_TC primary key (课程号, 教师号))go---------------------------建立课程号索引------------------------------ create index TC_FK on TC (课程号ASC)go--------------------------建立教师号索引------------------------------ create index TC2_FK on TC (教师号ASC)go---------------------------创建教师表------------------------------ create table Teacher (教师号varchar(5) not null,院系代号varchar(5) null,姓名varchar(6) null,性别char(2) null,年龄int null,工龄int null,备注varchar(16) null,constraint PK_TEACHER primary key (教师号))go---------------------------建立TD_FK 索引------------------------------ create index TD_FK on Teacher (院系代号ASC)goalter table Majoradd constraint FK_MAJOR_DM_DEPARTME foreign key (院系代号) references Department (院系代号)goalter table SCadd constraint FK_SC_SC_STUDENTS foreign key (学号)references S (学号)goadd constraint FK_SC_SC2_C foreign key (课程号)references C (课程号)goalter table Sadd constraint FK_STUDENTS_SD_DEPARTME foreign key (院系代号) references Department (院系代号)goalter table Sadd constraint FK_STUDENTS_SM_MAJOR foreign key (专业号) references Major (专业号)goalter table TCadd constraint FK_TC_TC_C foreign key (课程号)references C (课程号)goalter table TCadd constraint FK_TC_TC2_TEACHER foreign key (教师号)references Teacher (教师号)goalter table Teacheradd constraint FK_TEACHER_TD_DEPARTME foreign key (院系代号) references Department (院系代号)go触发器设计1、CREATE TRIGGER Supdate ON [dbo].[S]FOR UPDA TEASupdate SCset 学号= ( select 学号from inserted)where SC.学号=(select 学号from deleted) ;2、CREATE TRIGGER Sdelete ON [dbo].[StudentsInfo]FOR DELETEASDELETEFROM SCWHERE SC.学号=(select 学号from deleted) ;2. C表上的触发器:其功能是当一个课程的信息改变时,或当一个课程的信息被删除时,相应的在SC和TC表中的相应信息修改或删除。
系统源代码一、登录界面代码using System;using System.Data;using System。
Configuration;using System。
Collections;using System.Web;using System.Web。
Security;using System。
Web.UI;using System。
Web。
UI。
WebControls;using System.Web。
UI.WebControls。
WebParts;using System。
Web.UI.HtmlControls;using System.Data。
SqlClient;public partial class login :System.Web。
UI。
Page{protected void txtid_Click(object sender,EventArgs e){txtid.Text = ”";txtpassword。
Text = ””;}protected void Button1_Click(object sender, EventArgs e){string strconn = ConfigurationManager。
AppSettings[”connStr”];SqlConnection conn = new SqlConnection(strconn);conn。
Open();DataSet ds=new DataSet ();SqlDataAdapter da = new SqlDataAdapter("select * from users where userid=’" + txtid。
Text + "' and userpwd=’” + txtpassword.Text + ”’", conn);da.Fill(ds);if (ds。
XX学院计算机科学与技术系实验报告课程名称程序设计基础实验(2)实验项目应用系统的面向对象设计与分析实验类型综合性实验完成人所在班级指导教师完成日期2009年11月30日实验报告正文一.实验报告简表二.设计内容与要求设计内容:设计基于文件结构的学籍管理系统设计要求:(1)录入学生基本信息的功能界面(2)修改学生基本信息的功能界面(3)查询学生基本信息的功能界面(4)删除学生基本信息的功能界面三.总体设计,包括需求分析、功能描述、设计工具与运行环境、类及类间关系描述等a、Student.java:程序的入口。
初始化主界面,使主界面位于屏幕中间,且用户不能改变其大小。
b、MainFrame.java:程序的主界面。
由菜单、登陆界面和操作选项所构成。
其中菜单的“文件”中各操作项必须在登陆后方可选择,输入用户名和密码点击“进入”,提示登陆成功之后(用户名和密码在数据库的Admin表中,如果用户填的密码或用户名错误或没填都会产生相应的警告框),登陆界面消失,出现“添加信息”、“修改信息”、“信息查询”和“删除信息”四个按钮,且菜单中的操作项也被激活。
点击要操作的按钮或菜单项,进入要操作的界面(窗口出现在屏幕左上角)。
c、AddInf.java:添加信息界面。
按照要求添入基本信息,如果用户填错或没填,提示错误信息(如不能添加已经注册的学号)。
填写完整后,点击“增加”按钮,将信息加入数据库的BaseInf表中。
d、ChangeInf.java:修改信息界面。
按照提示输入要修改信息的学生学号,点击“下一步”(如果数据库无此学号,则提示“无此对应信息”),从数据库中将该学生的完整信息读出,用户修改之后点击“修改”即可。
注意:为了防止意外,修改学生信息时,程序禁止了对学号的修改。
(为了程序设计方便和代码重用,修改信息的代码是先删此该生所有信息,再将修改后的信息全部添加到数据库,这也是数据库修改的原理)e、SeachInf.java:查询信息界面。
输入要查询的学生的学号或姓名(也可两项都填写),点击“查询”,将提示“查无对应信息”或将查询到的学生完整信息显示出来,如果有多条对应信息,“下一条”按钮可选,单击之后可查看下一满足条件的信息,查找准确的学生信息。
f、DelInf.java:删除信息界面。
输入要删除信息的学生的学号,单击“下一步”,程序给出该生的完整信息,点击“删除”,提示是否确定删除对话框,仔细查看信息确认无误后,单击“确定”完成删除,否则单击“取消”。
四.详细设计,包括类图及代码等Student.java:import javax.swing.UIManager;import java.awt.*;public class Student {boolean packFrame = false;public Student() {MainFrame frame = new MainFrame();if (packFrame) {frame.pack();}else {frame.validate();}Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();Dimension frameSize = frame.getSize();if (frameSize.height > screenSize.height) {frameSize.height = screenSize.height;}if (frameSize.width > screenSize.width) {frameSize.width = screenSize.width;}frame.setLocation( (screenSize.width - frameSize.width) / 2,(screenSize.height - frameSize.height) / 2);frame.setVisible(true);}public static void main(String[] args) {try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}catch (Exception e) {e.printStackTrace();}new Student();}}MainFrame.java:import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;public class MainFrame extends JFrame {boolean login = false;JPanel contentPane;JMenuBar jMenuBar1 = new JMenuBar();/*菜单条*/JMenu jMenuFile = new JMenu();/*菜单项*/JMenu jMenuHelp = new JMenu();/*菜单项*/JMenuItem jMenuFileExit = new JMenuItem();/*菜单子项*/JMenuItem jMenuHelpAbout = new JMenuItem();/*菜单子项*/JMenuItem jMenuItem1 = new JMenuItem();/*菜单子项*/JMenuItem jMenuItem2 = new JMenuItem();/*菜单子项*/JMenuItem jMenuItem3 = new JMenuItem();/*菜单子项*/JMenuItem jMenuItem4 = new JMenuItem();/*菜单子项*/JMenuItem jMenuItem5 = new JMenuItem();/*菜单子项*/Label label1 = new Label();/*标签*/Label label2 = new Label();/*标签*/Label label3 = new Label();/*标签*/Label label4 = new Label();/*标签*/Button button1 = new Button();/*按钮*/Button button2 = new Button();/*按钮*/Button button3 = new Button();/*按钮*/Button button4 = new Button();/*按钮*/Button button5 = new Button();/*按钮*/TextField textField1 = new TextField();/*文本框*/TextField textField2 = new TextField();/*文本框*/public MainFrame() { /*构造函数*/enableEvents(AWTEvent.WINDOW_EVENT_MASK);try {jbInit();}catch (Exception e) {e.printStackTrace();}}private void jbInit() throws Exception { /*初始化*/contentPane = (JPanel)this.getContentPane();/*初始化一个容器*/contentPane.setLayout(null);contentPane.setEnabled(false);/*设置是否启用该组件FALSE表示不启用*/contentPane.setOpaque(true);/*该组件绘制其边界内的所有像素*/contentPane.setPreferredSize(new Dimension(1, 1));/*设置组建的首选大小*/contentPane.setRequestFocusEnabled(true);/*提供一个关于此JComponent 是否应该获得焦点的提示*/this.setForeground(Color.black);this.setResizable(false);/*设置此窗体为不可由用户调整大小*/this.setSize(new Dimension(400, 300));/*调整窗口大小宽为400高为300*/this.setTitle("学籍管理系统");jMenuBar1.setEnabled(true);jMenuBar1.setBorderPainted(true);/*如果该属性为true 并且按钮有边框,则绘制该边框*/jMenuFile.setVerifyInputWhenFocusTarget(true);/*设置该值指示是否在此组件请求焦点前,为当前的焦点所有者调用输入校验器*/jMenuFile.setActionCommand("文件");jMenuFile.setText("文件");jMenuHelp.setText("帮助");jMenuFileExit.setText("退出");jMenuFileExit.addActionListener(new MainFrame_ActionAdapter(this));jMenuHelpAbout.setText("关于");jMenuHelpAbout.addActionListener(new MainFrame_ActionAdapter(this));label1.setFont(new Font("Dialog", 1, 15));label1.setText("用户:");label1.setBounds(new Rectangle(123, 25, 49, 16));label2.setFont(new Font("Dialog", 1, 15));label2.setText("密码:");label2.setBounds(new Rectangle(123, 62, 49, 16));textField1.setText("");textField1.setBounds(new Rectangle(192, 24, 62, 18));textField2.setEchoChar('*');textField2.setText("");textField2.setBounds(new Rectangle(192, 61, 62, 18));button1.setLabel("进入系统");button1.setFont(new Font("Dialog", 1, 15));button1.setBounds(new Rectangle(150, 104, 101, 22));button1.addActionListener(new MainFrame_ActionAdapter(this));label3.setFont(new Font("Dialog", 1, 15));label3.setForeground(Color.red);label3.setText("请选择操作项");label3.setVisible(false);label3.setBounds(new Rectangle(158, 92, 84, 16));button2.setFont(new Font("Dialog", 1, 15));button2.setLabel("添加信息");button2.setVisible(false);button2.setBounds(new Rectangle(74, 136, 97, 33));button3.setFont(new Font("Dialog", 1, 15));button3.setLabel("修改信息");button3.setVisible(false);button3.setBounds(new Rectangle(226, 136, 97, 33));button4.setFont(new Font("Dialog", 1, 15));button4.setLabel("信息查询");button4.setVisible(false);button4.setBounds(new Rectangle(74, 185, 97, 33));button5.setFont(new Font("Dialog", 1, 15));button5.setLabel("删除信息");button5.setVisible(false);button5.setBounds(new Rectangle(226, 185, 97, 33));jMenuItem1.setText("添加信息");jMenuItem2.setText("信息查询");jMenuItem3.setText("修改信息");jMenuItem4.setText("删除信息");jMenuItem5.setText("帮助");label4.setFont(new Font("Dialog", 1, 30));label4.setText("学籍管理系统");label4.setVisible(false);label4.setBounds(new Rectangle(70, 37, 261, 33));jMenuFile.add(jMenuItem1);jMenuItem1.setEnabled(false);jMenuItem1.addActionListener(new MainFrame_ActionAdapter(this)); jMenuItem2.setEnabled(false);jMenuFile.add(jMenuItem2);jMenuItem2.addActionListener(new MainFrame_ActionAdapter(this)); jMenuItem3.setEnabled(false);jMenuFile.add(jMenuItem3);jMenuItem3.addActionListener(new MainFrame_ActionAdapter(this)); jMenuItem4.setEnabled(false);jMenuFile.add(jMenuItem4);jMenuItem4.addActionListener(new MainFrame_ActionAdapter(this)); jMenuFile.add(jMenuFileExit);jMenuHelp.add(jMenuItem5);jMenuHelp.add(jMenuHelpAbout);jMenuBar1.add(jMenuFile);jMenuBar1.add(jMenuHelp);contentPane.add(label1, null);contentPane.add(label2, null);contentPane.add(textField1, null);contentPane.add(textField2, null);contentPane.add(label3, null);contentPane.add(button2, null);button2.addActionListener(new MainFrame_ActionAdapter(this)); contentPane.add(button4, null);button4.addActionListener(new MainFrame_ActionAdapter(this)); contentPane.add(button3, null);button3.addActionListener(new MainFrame_ActionAdapter(this)); contentPane.add(button5, null);button5.addActionListener(new MainFrame_ActionAdapter(this));contentPane.add(button1, null);contentPane.add(label4, null);this.setJMenuBar(jMenuBar1);}public void jMenuFileExit_actionPerformed(ActionEvent e) {System.exit(0);}public void jMenuHelpAbout_actionPerformed(ActionEvent e) {}protected void processWindowEvent(WindowEvent e) {super.processWindowEvent(e);if (e.getID() == WindowEvent.WINDOW_CLOSING) {jMenuFileExit_actionPerformed(null);}}void button1_actionPerformed(ActionEvent e) {String user = textField1.getText().trim();String pass = textField2.getText().trim();try {String strurl ="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/student.mdb";Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection conn = DriverManager.getConnection(strurl);Statement stmt = conn.createStatement();if (user.equals("")|| pass.equals(""))JOptionPane.showMessageDialog(null, "用户名或密码不能为空", "警告",JOptionPane.W ARNING_MESSAGE);else {ResultSet rs = stmt.executeQuery("select * from admin where username='" +user + "' AND password='" + pass + "'");if (rs.next()) {JOptionPane.showMessageDialog(null, "登陆成功");login = true;label1.setVisible(false);textField1.setVisible(false);label2.setVisible(false);textField2.setVisible(false);button1.setVisible(false);label3.setVisible(true);label4.setVisible(true);button2.setVisible(true);button3.setVisible(true);button4.setVisible(true);button5.setVisible(true);jMenuItem1.setEnabled(true);jMenuItem2.setEnabled(true);jMenuItem3.setEnabled(true);jMenuItem4.setEnabled(true);}elseJOptionPane.showMessageDialog(null, "登陆失败", "警告",JOptionPane.W ARNING_MESSAGE);}}catch (Exception eg){eg.printStackTrace();}}}class MainFrame_ActionAdapter implements ActionListener {MainFrame adaptee;MainFrame_ActionAdapter(MainFrame adaptee) {this.adaptee = adaptee;}public void actionPerformed(ActionEvent e) {if (e.getSource() == adaptee.jMenuFileExit)adaptee.jMenuFileExit_actionPerformed(e);else if (e.getSource() == adaptee.jMenuItem1 ||e.getSource() == adaptee.button2) {AddInf addInf = new AddInf();addInf.setSize(400, 300);addInf.setVisible(true);}else if (e.getSource() == adaptee.jMenuItem3 ||e.getSource() == adaptee.button3) {ChangeInf changeInf = new ChangeInf();changeInf.setSize(400, 300);changeInf.setVisible(true);}else if (e.getSource() == adaptee.jMenuItem2 ||e.getSource() == adaptee.button4) {SearchInf searchInf = new SearchInf();searchInf.setSize(400, 300);searchInf.setVisible(true);}else if (e.getSource() == adaptee.jMenuItem4 ||e.getSource() == adaptee.button5) {DelInf delInf = new DelInf();delInf.setSize(400, 300);delInf.setVisible(true);}else if (e.getSource() == adaptee.jMenuHelpAbout)adaptee.jMenuHelpAbout_actionPerformed(e);else if (e.getSource() == adaptee.button1)adaptee.button1_actionPerformed(e);}}AddInf.javaimport javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class AddInf extends JFrame implements ActionListener { Label label1 = new Label();TextField textField1 = new TextField();Label label2 = new Label();TextField textField2 = new TextField();Label label3 = new Label();Choice choice1 = new Choice();Label label4 = new Label();TextField textField3 = new TextField();Label label5 = new Label();Choice choice2 = new Choice();Label label6 = new Label();TextField textField4 = new TextField();Label label7 = new Label();Choice choice3 = new Choice();Label label8 = new Label();TextField textField5 = new TextField();Label label9 = new Label();TextArea textArea1 = new TextArea();Button button1 = new Button();public AddInf() {try {jbInit();}catch (Exception e) {e.printStackTrace();}}private void jbInit() throws Exception {this.setEnabled(true);this.setResizable(false);this.setTitle("增加学生信息");this.setDefaultCloseOperation(HIDE_ON_CLOSE); label1.setText("学号:");label1.setBounds(new Rectangle(30, 11, 51, 33)); this.getContentPane().setLayout(null);textField1.setText("");textField1.setBounds(new Rectangle(86, 16, 74, 22)); label2.setText("姓名:");label2.setBounds(new Rectangle(162, 11, 28, 33)); textField2.setText("");textField2.setBounds(new Rectangle(192, 16, 44, 22)); label3.setText("性别:");label3.setBounds(new Rectangle(241, 11, 28, 33)); choice1.setEnabled(true);choice1.setFont(new Font("Dialog", 0, 12));choice1.setForeground(Color.black);choice1.setLocale(java.util.Locale.getDefault()); choice1.setVisible(true);choice1.setBounds(new Rectangle(275, 15, 50, 25)); choice1.addItem("男");choice1.addItem("女");label4.setText("出生日期:");label4.setBounds(new Rectangle(31, 53, 49, 33)); textField3.setText("YYYY-MM-DD");textField3.setBounds(new Rectangle(86, 58, 74, 22)); label5.setText("政治面貌:");label5.setBounds(new Rectangle(241, 53, 47, 33)); choice2.setBounds(new Rectangle(296, 57, 72, 25)); choice2.setVisible(true);choice2.setLocale(java.util.Locale.getDefault()); choice2.setForeground(Color.black);choice2.setFont(new Font("Dialog", 0, 12));choice2.setEnabled(true);label6.setText("籍贯:");label6.setBounds(new Rectangle(163, 53, 26, 33)); textField4.setText("");textField4.setBounds(new Rectangle(191, 58, 44, 22)); label7.setText("系别:");label7.setBounds(new Rectangle(30, 94, 50, 33)); choice3.setEnabled(true);choice3.setFont(new Font("Dialog", 0, 12));choice3.setForeground(Color.black);choice3.setLocale(java.util.Locale.getDefault()); choice3.setVisible(true);choice3.setBounds(new Rectangle(86, 98, 75, 25)); label8.setText("专业:");label8.setBounds(new Rectangle(163, 94, 26, 33)); textField5.setText("");textField5.setBounds(new Rectangle(190, 99, 178, 22)); label9.setText("备注:");label9.setBounds(new Rectangle(27, 132, 50, 33)); textArea1.setBounds(new Rectangle(84, 139, 285, 92)); button1.setLabel("增加");button1.setVisible(true);button1.setBounds(new Rectangle(156, 244, 89, 22)); button1.addActionListener(this);this.getContentPane().add(label3, null);this.getContentPane().add(label1, null);this.getContentPane().add(textField1, null);this.getContentPane().add(label2, null);this.getContentPane().add(textField2, null);this.getContentPane().add(choice1, null);this.getContentPane().add(label4, null);this.getContentPane().add(textField3, null);this.getContentPane().add(label6, null);this.getContentPane().add(textField4, null);this.getContentPane().add(label5, null);this.getContentPane().add(choice2, null);this.getContentPane().add(label7, null);this.getContentPane().add(choice3, null);this.getContentPane().add(label8, null);this.getContentPane().add(textField5, null);this.getContentPane().add(label9, null);this.getContentPane().add(textArea1, null);this.getContentPane().add(button1, null);choice2.addItem("团员");choice2.addItem("党员");choice2.addItem("其他");choice3.addItem("计算机");choice3.addItem("电子");choice3.addItem("生化");choice3.addItem("艺术");}public void actionPerformed(ActionEvent e) {try {String strurl ="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/student.mdb";Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection conn = DriverManager.getConnection(strurl);Statement stmt = conn.createStatement();ResultSet rs = stmt.executeQuery("select 学号from BaseInf where 学号='" +textField1.getText() + "'");if (rs.next()) {JOptionPane.showMessageDialog(null, "此学号已经被注册.", "警告",JOptionPane.W ARNING_MESSAGE);return;}stmt.execute("insert into BaseInf (学号,系别,专业,姓名,性别,出年日期,籍贯,政治面貌,备注) values ('" +textField1.getText() + "','" + choice3.getSelectedItem() + "','" +textField5.getText() + "','" + textField2.getText() + "','" +choice1.getSelectedItem() + "','" + textField3.getText() + "','" +textField4.getText() + "','" + choice2.getSelectedItem() + "','" +textArea1.getText() + "')");textField1.setText("");textField2.setText("");textField3.setText("");textField4.setText("");textField5.setText("");textArea1.setText("");JOptionPane.showMessageDialog(null, "增加信息成功!");}catch (Exception eg) {JOptionPane.showMessageDialog(null, "请认真检查各项(不能为空),\n日期要合法!然后重试.", "异常警告",JOptionPane.WARNING_MESSAGE);eg.printStackTrace();}}}ChangeInf.java:import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class ChangeInf extends JFrame implements ActionListener { String strurl;Connection conn;Statement stmt;ResultSet rs;Label label1 = new Label();TextField textField1 = new TextField();Label label2 = new Label();TextField textField2 = new TextField();Label label3 = new Label();Choice choice1 = new Choice();Label label4 = new Label();TextField textField3 = new TextField();Label label5 = new Label();Choice choice2 = new Choice();Label label6 = new Label();TextField textField4 = new TextField();Label label7 = new Label();Choice choice3 = new Choice();Label label8 = new Label();TextField textField5 = new TextField();Label label9 = new Label();TextArea textArea1 = new TextArea();Button button1 = new Button();TextField textField6 = new TextField();Button button2 = new Button();Label label10 = new Label();public ChangeInf() {try {jbInit();}catch (Exception e) {e.printStackTrace();}}private void jbInit() throws Exception {label1.setText("学号:");label1.setVisible(false);label1.setBounds(new Rectangle(30, 11, 51, 33)); this.getContentPane().setLayout(null);textField1.setText("");textField1.setVisible(false);textField1.setBounds(new Rectangle(86, 16, 74, 22)); label2.setBounds(new Rectangle(162, 11, 28, 33)); label2.setText("姓名:");label2.setVisible(false);textField2.setText("");textField2.setVisible(false);textField2.setBounds(new Rectangle(192, 16, 44, 22)); label3.setText("性别:");label3.setVisible(false);label3.setBounds(new Rectangle(241, 11, 28, 33)); choice1.setEnabled(true);choice1.setFont(new Font("Dialog", 0, 12));choice1.setForeground(Color.black);choice1.setLocale(java.util.Locale.getDefault()); choice1.setVisible(false);choice1.setBounds(new Rectangle(275, 15, 50, 25)); choice1.addItem("男");choice1.addItem("女");this.setDefaultCloseOperation(HIDE_ON_CLOSE); this.setEnabled(true);this.setResizable(false);this.setTitle("修改学生信息");label4.setBounds(new Rectangle(31, 53, 49, 33)); label4.setText("出生日期:");label4.setVisible(false);textField3.setBounds(new Rectangle(86, 58, 74, 22)); textField3.setLocale(java.util.Locale.getDefault()); textField3.setText("");textField3.setVisible(false);label5.setText("政治面貌:");label5.setVisible(false);label5.setBounds(new Rectangle(241, 53, 47, 33)); choice2.setBounds(new Rectangle(296, 57, 72, 25)); choice2.setVisible(false);choice2.setLocale(java.util.Locale.getDefault()); choice2.setForeground(Color.black);choice2.setFont(new Font("Dialog", 0, 12));choice2.setEnabled(true);label6.setText("籍贯:");label6.setVisible(false);label6.setBounds(new Rectangle(163, 53, 26, 33)); textField4.setBounds(new Rectangle(191, 58, 44, 22)); textField4.setText("");textField4.setVisible(false);label7.setBounds(new Rectangle(30, 94, 50, 33));label7.setText("系别:");label7.setVisible(false);choice3.setEnabled(true);choice3.setFont(new Font("Dialog", 0, 12));choice3.setForeground(Color.black);choice3.setLocale(java.util.Locale.getDefault()); choice3.setVisible(false);choice3.setBounds(new Rectangle(86, 98, 75, 25)); label8.setBounds(new Rectangle(163, 94, 26, 33)); label8.setText("专业:");label8.setVisible(false);textField5.setText("");textField5.setVisible(false);textField5.setBounds(new Rectangle(190, 99, 178, 22)); label9.setText("备注:");label9.setVisible(false);label9.setBounds(new Rectangle(27, 132, 50, 33)); textArea1.setVisible(false);textArea1.setBounds(new Rectangle(84, 139, 285, 95)); button1.setLabel("修改");button1.setVisible(false);button1.setBounds(new Rectangle(153, 241, 94, 22)); button1.addActionListener(this);textField6.setText("");textField6.setBounds(new Rectangle(147, 92, 105, 23)); button2.setFont(new Font("Dialog", 1, 15));button2.setLabel("下一步");button2.setVisible(true);button2.setBounds(new Rectangle(156, 148, 89, 23)); button2.addActionListener(this);label10.setFont(new Font("Dialog", 1, 15));label10.setText("请输入要修改的学生学号");label10.setBounds(new Rectangle(110, 49, 178, 24)); this.getContentPane().add(label3, null);this.getContentPane().add(label1, null);this.getContentPane().add(textField1, null);this.getContentPane().add(label2, null);this.getContentPane().add(textField2, null);this.getContentPane().add(choice1, null);this.getContentPane().add(label4, null);this.getContentPane().add(textField3, null);this.getContentPane().add(label6, null);this.getContentPane().add(textField4, null);this.getContentPane().add(label5, null);this.getContentPane().add(choice2, null);this.getContentPane().add(label7, null);this.getContentPane().add(choice3, null);this.getContentPane().add(label8, null);this.getContentPane().add(textField5, null);this.getContentPane().add(label9, null);this.getContentPane().add(textArea1, null);this.getContentPane().add(button2, null);this.getContentPane().add(textField6, null);this.getContentPane().add(label10, null);this.getContentPane().add(button1, null);choice2.addItem("团员");choice2.addItem("党员");choice2.addItem("其他");choice3.addItem("计算机");choice3.addItem("电子");choice3.addItem("生化");choice3.addItem("艺术");strurl ="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/student.mdb"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");conn = DriverManager.getConnection(strurl);stmt = conn.createStatement();}public void actionPerformed(ActionEvent e) {if (e.getSource() == button2) {try {rs = stmt.executeQuery("SELECT * FROM BaseInf where 学号='" +textField6.getText() + "'");if (rs.next()) {textField6.setVisible(false);button2.setVisible(false);label10.setVisible(false);label1.setVisible(true);label2.setVisible(true);label3.setVisible(true);label4.setVisible(true);label5.setVisible(true);label6.setVisible(true);label7.setVisible(true);label8.setVisible(true);label9.setVisible(true);textArea1.setVisible(true);textArea1.setText(rs.getString("备注"));textField1.setVisible(true);textField1.enable(false);textField1.setText(rs.getString("学号"));textField2.setVisible(true);textField2.setText(rs.getString("姓名"));textField3.setVisible(true);textField3.setText(rs.getString("出年日期"));textField4.setVisible(true);textField4.setText(rs.getString("籍贯"));textField5.setVisible(true);textField5.setText(rs.getString("专业"));choice1.setVisible(true);choice1.select(rs.getString("性别"));choice2.setVisible(true);choice2.select(rs.getString("政治面貌"));choice3.setVisible(true);choice3.select(rs.getString("系别"));button1.setVisible(true);}elseJOptionPane.showMessageDialog(null, "无此学号对应信息", "警告",JOptionPane.W ARNING_MESSAGE);}catch (Exception eg) {eg.printStackTrace();}}else if (e.getSource() == button1) {try {stmt.execute("DELETE * FROM BaseInf where 学号='" + textField1.getText() +"'");stmt.execute("insert into BaseInf (学号,系别,专业,姓名,性别,出年日期,籍贯,政治面貌,备注) values ('" +textField1.getText() + "','" + choice3.getSelectedItem() + "','" +textField5.getText() + "','" + textField2.getText() + "','" +choice1.getSelectedItem() + "','" + textField3.getText() + "','" +textField4.getText() + "','" + choice2.getSelectedItem() + "','" +textArea1.getText() + "')");JOptionPane.showMessageDialog(null, "修改信息成功!");}catch (Exception eg) {JOptionPane.showMessageDialog(null, "请认真检查各项(不能为空),\n日期要合法!然后重试.","异常警告", JOptionPane.W ARNING_MESSAGE);eg.printStackTrace();}}}}SearchInf.java:import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class SearchInf extends JFrame implements ActionListener {String strurl;Connection conn;Statement stmt;ResultSet rs;Label label1 = new Label();TextField textField1 = new TextField();Label label2 = new Label();TextField textField2 = new TextField();Label label3 = new Label();Choice choice1 = new Choice();Label label4 = new Label();TextField textField3 = new TextField();Label label5 = new Label();Choice choice2 = new Choice();Label label6 = new Label();TextField textField4 = new TextField();Label label7 = new Label();Choice choice3 = new Choice();Label label8 = new Label();TextField textField5 = new TextField();Label label9 = new Label();TextArea textArea1 = new TextArea();Button button1 = new Button();TextField textField6 = new TextField();Button button2 = new Button();Label label10 = new Label();Label label12 = new Label();Label label13 = new Label();TextField textField7 = new TextField();public SearchInf() {try {jbInit();}catch (Exception e) {e.printStackTrace();}}private void jbInit() throws Exception {label1.setText("学号:");label1.setVisible(false);label1.setBounds(new Rectangle(30, 11, 51, 33)); this.getContentPane().setLayout(null);textField1.setText("");textField1.setVisible(false);textField1.setBounds(new Rectangle(86, 16, 74, 22)); label2.setBounds(new Rectangle(162, 11, 28, 33)); label2.setText("姓名:");label2.setVisible(false);textField2.setText("");textField2.setVisible(false);textField2.setBounds(new Rectangle(192, 16, 44, 22)); label3.setText("性别:");label3.setVisible(false);label3.setBounds(new Rectangle(241, 11, 28, 33)); choice1.setEnabled(true);choice1.setFont(new java.awt.Font("Dialog", 0, 12)); choice1.setForeground(Color.black);choice1.setLocale(java.util.Locale.getDefault()); choice1.setVisible(false);choice1.setBounds(new Rectangle(275, 15, 50, 25)); choice1.addItem("男");choice1.addItem("女");this.setDefaultCloseOperation(HIDE_ON_CLOSE); this.setEnabled(true);this.setResizable(false);this.setTitle("查询学生信息");label4.setBounds(new Rectangle(31, 53, 49, 33)); label4.setText("出生日期:");。