JAVA课程设计.docx
- 文档编号:967241
- 上传时间:2023-04-30
- 格式:DOCX
- 页数:26
- 大小:23.17KB
JAVA课程设计.docx
《JAVA课程设计.docx》由会员分享,可在线阅读,更多相关《JAVA课程设计.docx(26页珍藏版)》请在冰点文库上搜索。
JAVA课程设计
课程设计(论文)任务书
学院
数学学院
专业
信息与计算科学
学生姓名
王继禹
学号
0335
课程设计
题目
红河学院成绩查询
内容及要求:
1.根据学号查询学生成绩;
2.可以按学年、学期查询。
评语
年月日
成绩:
指导教师(签字):
年月日
指导、检查记录
日期
功能
完成情况
评分
1题目要求
红河学院成绩查询
功能要求:
1.根据学号查询学生成绩;
2.可以按学年、学期查询。
2系统设计
描述为完成题目要求的系统设计,设计可以是按功能,或步骤分解,分解之后的内容要可检查,有相应的代码或文档说明这部分功能。
重点介绍自己负责部分的功能设计,设计可以包括功能模块图、必要的UML图,
2.1功能模块设计1
2.1.1功能说明:
1.创建主类MainFrame,下含4个类,对4个事件按钮添加监控,实现按钮事件为对应类的对象,出现相应功能窗口。
2.创建添加类Insert,题目虽只要求查询学生成绩,但我们不可能再代码中添加学生成绩,故需创建添加按钮,对按钮添加监控,实现按钮事件为获取文本域中的信息。
3.创建查询类QUERY,按照题目要求,分别创建学号,学年,学期三个查询按钮,此外,为了便于查询,又创建姓名和课程两个查询按钮以及一个显示全部信息的按钮。
4.创建修改类Modify,因存在添加类Insert,为了防止添加学生成绩信息时出现错误,故应当建立修改按钮,与添加数据类似,对按钮添加监控,实现按钮事件为获取文本域中的信息,不同的是以学号为主键进行查找并更新。
5.创建删除类Delete,同理,当学生成绩信息过多时进行删除,且使得窗口界面整洁合理。
与修改数据类似,对按钮添加监控,实现按钮事件为获取文本域中的学号信息,不同的是以学号为主键进行查找并将删除信息输出到文本框中。
2.1.2必要知识点:
1.创建图形界面需运用到GUI语句,可参考课本355页的知识。
2.创建图形界面以后需要创建相关按钮,每一个按钮对应一个相关功能类。
3.为每一个按钮添加监听。
4.大致完成以后,修改界面,使其整洁有序,并可以修改界面大小,按钮颜色。
5.添加与修改两个类需要连接到SQL2008数据库,在数据库中进行信息的添加与删除。
2.2功能模块设计2
2.2.1系统逻辑结构设计
学生成绩信息表
字段名
属性
类型
空值
约束条件
学号
Sno
文本
notnull
主键
姓名
name
文本
从键
学年
Year
文本
从简
学期
Semester
文本
从简
语文
Chinese
长整数
英语
English
长整数
数学
Maths
长整数
2.2.2程序运行代码
MainFrame类:
packagedazuoye;
import.*;
import.*;
import.*;
publicclassMainFrameextendsJFrame{
JButtoninsert,query,delete,modify;
JPanelpanel,panel1,panel2;
publicMainFrame(){
dd(picture,newInteger);
Toolkitkit=();
DimensionscreenSize=();
intscreenWidth=/2;
intscreenHeight=/2;
intheight=();
intwidth=();
(0,0,360,360);
((JPanel)contentPane).setOpaque(false);
(screenWidth-width/2,screenHeight-height/2);
(true);
}
publicclassinsertActionPerformedimplementsActionListener{
publicvoidactionPerformed(ActionEvente){
newInsert().setVisible(true);
}
}
publicclassmodifyActionPerformedimplementsActionListener{
publicvoidactionPerformed(ActionEvente){
newModify().setVisible(true);
}
}
publicclassqueryActionPerformedimplementsActionListener{
publicvoidactionPerformed(ActionEvente){
newQuery().setVisible(true);
}
}
publicclassdeleteActionPerformedimplementsActionListener{
publicvoidactionPerformed(ActionEvente){
newDelete().setVisible(true);
}
}
publicstaticvoidmain(String[]args){
newMainFrame();
}
}
Insert类:
packagedazuoye;
import.*;
import.*;
import.*;
publicclassInsertextendsJFrame{
JTextFieldinput1,input2,input3,input4,input5,input6,input7;
JLabellabel1,label2,label3,label4,label5;
JButtonbutton;
staticStatementst;
static{
try{
("");
Connectioncon=("jdbc:
odbc:
student");
st=();
}catch(Exceptione){
}
}
ResultSetrs;
publicInsert(){
input1=newJTextField(15);
input2=newJTextField(15);
input3=newJTextField(15);
input4=newJTextField(15);
input5=newJTextField(15);
input6=newJTextField(15);
input7=newJTextField(15);
JPanelpanel=newJPanel();
(newGridLayout(7,2));
(newJLabel("学号"),;
(input1);
(newJLabel("姓名"),;
(input2);
(newJLabel("学年"),;
(input3);
(newJLabel("学期"),;
(input4);
(newJLabel("语文"),;
(input5);
(newJLabel("英语"),;
(input6);
(newJLabel("数学"),;
(input7);
button=newJButton("添加");
(newmysql());
Containercontainer=getContentPane();
(panel,;
(button,;
setTitle("添加数据窗口");
setDefaultCloseOperation;
setSize(300,300);
Toolkitkit=();
DimensionscreenSize=();
intscreenWidth=/2;
intscreenHeight=/2;
intheight=();
intwidth=();
setLocation(screenWidth-width/2,screenHeight-height/2);
setVisible(true);
}
classmysqlimplementsActionListener{
publicvoidactionPerformed(ActionEvente){
try{
Stringsno=().trim();
Stringname=().trim();
Stringyear=().trim();
Stringsemester=().trim();
Stringchinese=().trim();
Stringenglish=().trim();
Stringmaths=().trim();
if("")|("")|("")|("")|("")|("")|("")){
"请重新输入","提示对话框",1);
}else{
Stringsql="insertintoScoreInfo(ID,name,year,semester,Chinese,English,Maths)values('"+sno+"','"
+name+"','"+year+"',"+semester+"',"+chinese+","+english+","+maths+");";
(sql);
"数据添加成功","提示对话框",1);
("");
("");
("");
("");
("");
("");
("");
}
}catch(Exceptionee){
}
}
}
}
QUERY类:
packagedazuoye;
import.*;
import.*;
import.*;
publicclassQueryextendsJFrame{
JTextAreashow;
JButtonbutton1,button2,button3,button4,button5,button6;;
JTextFieldfield1,field2,field3,field4;
JComboBoxcomoBox;
staticStatementst;
static{
try{
("");
Connectioncon=("jdbc:
odbc:
student");
st=();
}catch(Exceptione){
}
}
publicQuery(){
show=newJTextArea(6,15);
button1=newJButton("显示所有信息");
(newMysql1());
Containercontainer=getContentPane();
(newBorderLayout());
JPanelpanel=newJPanel();
JPanelmainpanel=newJPanel();
button2=newJButton("按学号查询");
(newMysql2());
(button2);
field1=newJTextField(7);
(field1);
(true);
(panel);
button3=newJButton("按姓名查询");
(newMysql3());
(button3);
field2=newJTextField(6);
(field2);
(true);
(panel);
button4=newJButton("按学年查询");
(newMysql4());
(button4);
field3=newJTextField(6);
(field3);
(true);
(panel);
button5=newJButton("按学期查询");
(newMysql4());
(button5);
field4=newJTextField(6);
(field4);
(true);
(panel);
Stringitems[]={"请选择","语文","英语","数学"};
comoBox=newJComboBox(items);
button6=newJButton("按课程名称查询");
(newMysql5());
(button6);
(comoBox);
(true);
(panel);
panel=newJPanel();
(button1);
(mainpanel,;
(panel,;
(newJScrollPane(show),;
setTitle("查询数据");
setDefaultCloseOperation;
setSize(1000,400);
Toolkitkit=();
DimensionscreenSize=();
intscreenWidth=/2;
intscreenHeight=/2;
intheight=();
intwidth=();
setLocation(screenWidth-width/2,screenHeight-height/2);
setVisible(true);
}
classMysql1implementsActionListener{
publicvoidactionPerformed(ActionEvente){
try{
Stringsql="select*fromScoreInfo";
ResultSetrs=(sql);
("");
(
"序号学号姓名学年学期语文英语数学"
+"\n");
while()){
(1)+"");
(2)+"");
(3)+"");
(4)+"");
(5)+"");
(6)+"");
(7)+"");
(8)+"\n");
}
}catch(Exceptionee){
}
}
}
classMysql2implementsActionListener{
publicvoidactionPerformed(ActionEvente){
try{
Stringss=().trim();
Stringsql="select*fromScoreInfowhereID='"+ss+"'";
ResultSetrs=(sql);
("");
(
"序号学号姓名学年学期语文英语数学"
+"\n");
while()){
(1)+"");
(2)+"");
(3)+"");
(4)+"");
(5)+"");
(6)+"");
(7)+"");
(8)+"\n");
}
}catch(Exceptionee){
}
}
}
classMysql3implementsActionListener{
publicvoidactionPerformed(ActionEvente){
try{
Stringss=().trim();
Stringsql="select*fromScoreInfowherename='"+ss+"'";
ResultSetrs=(sql);
("");
(
"序号学号姓名学年学期语文英语数学"
+"\n");
while()){
(1)+"");
(2)+"");
(3)+"");
(4)+"");
(5)+"");
(6)+"");
(7)+"");
(8)+"\n");
}
}catch(Exceptionee){
}
}
}
classMysql4implementsActionListener{
publicvoidactionPerformed(ActionEvente){
try{
Stringss=().trim();
Stringsql="select*fromScoreInfowhereclass='"+ss+"'";
ResultSetrs=(sql);
("");
(
"序号学号姓名学年学期语文英语数学"
+"\n");
while()){
(1)+"");
(2)+"");
(3)+"");
(4)+"");
(5)+"");
(6)+"");
(7)+"");
(8)+"\n");
}
}catch(Exceptionee){
}
}
}
classMysql5implementsActionListener{
publicvoidactionPerformed(ActionEvente){
try{
Stringss=().trim();
Stringsql="select*fromScoreInfowhereclass='"+ss+"'";
ResultSetrs=(sql);
("");
(
"序号学号姓名学年学期语文英语数学"
+"\n");
while()){
(1)+"");
(2)+"");
(3)+"");
(4)+"");
(5)+"");
(6)+"");
(7)+"");
(8)+"\n");
}
}catch(Exceptionee){
}
}
}
classMysql6implementsActionListener{
publicvoidactionPerformed(ActionEvente){
try{
Stringsql="";
Stringss=().toString();
if("语文")){
sql="selectID,name,year,semester,ChinesefromScoreInfo";
("");
(
"序号学号姓名学年学期语文"
+"\n");
}elseif("英语")){
sql="selectID,name,year,semester,EnglishfromScoreInfo";
("");
(
"序号学号姓名学年学期英语"
+"\n");
}elseif("数学")){
sql="selectID,name,year,semester,MathsfromScoreInfo";
("");
(
"序号学号姓名学年学期数学"
+"\n");
}
ResultSetrs=(sql);
inti=0;
while()){
i++;
(""+i+""+
(1)+"");
(2)+"");
(3)+"");
(4)+"\n");
}
}catch(Exceptionee){
}
}
}
}
Modify类:
packagedazuoye;
import.*;
import.*;
import.*;
publicclassModifyextendsJFrame{
JTextFieldinput1,input2,input3,input4,input5,inp
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- JAVA 课程设计