JAVA课程设计Word格式.docx
《JAVA课程设计Word格式.docx》由会员分享,可在线阅读,更多相关《JAVA课程设计Word格式.docx(26页珍藏版)》请在冰点文库上搜索。
![JAVA课程设计Word格式.docx](https://file1.bingdoc.com/fileroot1/2023-4/30/a34b76a8-164b-47a5-b6d0-df3fa2a218ba/a34b76a8-164b-47a5-b6d0-df3fa2a218ba1.gif)
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.*;
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{
newModify().setVisible(true);
publicclassqueryActionPerformedimplementsActionListener{
newQuery().setVisible(true);
publicclassdeleteActionPerformedimplementsActionListener{
newDelete().setVisible(true);
publicstaticvoidmain(String[]args){
newMainFrame();
}
Insert类:
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);
姓名"
(input2);
学年"
(input3);
学期"
(input4);
语文"
(input5);
英语"
(input6);
数学"
(input7);
button=newJButton("
添加"
(newmysql());
Containercontainer=getContentPane();
(panel,;
(button,;
setTitle("
添加数据窗口"
setDefaultCloseOperation;
setSize(300,300);
setLocation(screenWidth-width/2,screenHeight-height/2);
setVisible(true);
classmysqlimplementsActionListener{
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);
数据添加成功"
("
}
}catch(Exceptionee){
}
QUERY类:
publicclassQueryextendsJFrame{
JTextAreashow;
JButtonbutton1,button2,button3,button4,button5,button6;
JTextFieldfield1,field2,field3,field4;
JComboBoxcomoBox;
publicQuery(){
show=newJTextArea(6,15);
button1=newJButton("
显示所有信息"
(newMysql1());
(newBorderLayout());
JPanelmainpanel=newJPanel();
button2=newJButton("
按学号查询"
(newMysql2());
(button2);
field1=newJTextField(7);
(field1);
(panel);
button3=newJButton("
按姓名查询"
(newMysql3());
(button3);
field2=newJTextField(6);
(field2);
button4=newJButton("
按学年查询"
(newMysql4());
(button4);
field3=newJTextField(6);
(field3);
button5=newJButton("
按学期查询"
(button5);
field4=newJTextField(6);
(field4);
Stringitems[]={"
请选择"
};
comoBox=newJComboBox(items);
button6=newJButton("
按课程名称查询"
(newMysql5());
(button6);
(comoBox);
panel=newJPanel();
(button1);
(mainpanel,;
(newJScrollPane(show),;
查询数据"
setSize(1000,400);
classMysql1implementsActionListener{
Stringsql="
select*fromScoreInfo"
ResultSetrs=(sql);
("
(
"
序号学号姓名学年学期语文英语数学"
+"
\n"
while()){
(1)+"
"
(2)+"
(3)+"
(4)+"
(5)+"
(6)+"
(7)+"
(8)+"
classMysql2implementsActionListener{
Stringss=().trim();
select*fromScoreInfowhereID='
+ss+"
classMysql3implementsActionListener{
select*fromScoreInfowherename='
classMysql4implementsActionListener{
select*fromScoreInfowhereclass='
classMysql5implementsActionListener{
classMysql6implementsActionListener{
Stringss=().toString();
sql="
selectID,name,year,semester,ChinesefromScoreInfo"
(
"
序号学号姓名学年学期语文"
+"
}elseif("
selectID,name,year,semester,EnglishfromScoreInfo"
序号学号姓名学年学期英语"
selectID,name,year,semester,MathsfromScoreInfo"
序号学号姓名学年学期数学"
inti=0;
i++;
+i+"
+
(1)+"
Modify类:
publicclassModifyextendsJFrame{
JTextFieldinput1,input2,input3,input4,input5,inp