




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、Java語言程序設(shè)計B報 告班級: 192091-27 學(xué)號: 20091003757 姓名: 羅 斌 成績: 2012年1月一個簡單的學(xué)生成績管理信息系統(tǒng)題目:數(shù)據(jù)庫要求:1. 建立的數(shù)據(jù)庫中包含如下信息:學(xué)生學(xué)號、姓名、班級,語文、數(shù)學(xué)、英語成績。2. 至少要有5個班級,每個班級要有10名以上學(xué)生。3. 使用.txt格式文本表示各種表。功能需求:1. 能夠?qū)崿F(xiàn)根據(jù)以下關(guān)鍵字查詢:學(xué)生姓名 、學(xué)號、班級、課程名稱。2. 能夠?qū)崿F(xiàn)按照單科成績、總成績、平均成績、學(xué)號排序。3. 能夠?qū)崿F(xiàn)學(xué)生信息的插入、刪除和修改。4. 能夠查詢每個課程的最高分、最低分及相應(yīng)學(xué)生姓名、班級和學(xué)號。5. 能夠查詢每
2、個班級某門課程的優(yōu)秀率(90分及以上)、不及格率,并進(jìn)行排序。界面要求: 使用圖形界面實(shí)現(xiàn),要符合日常軟件使用規(guī)范來設(shè)計菜單和界面。一、需求分析 1、界面 符合日常軟件使用規(guī)范,使用方便,外形簡潔美觀。 2、功能需求 存儲學(xué)生學(xué)號、姓名、班級,語文、數(shù)學(xué)、英語成績等信息,實(shí)現(xiàn)數(shù)據(jù)庫的讀取與存入,數(shù)據(jù)項的記錄與修改,刪除等。二、設(shè)計思想 1、類設(shè)計 將添加數(shù)據(jù)、查詢數(shù)據(jù)、刪除數(shù)據(jù)、修改數(shù)據(jù)四個功能分別為四個類來實(shí)現(xiàn),為了便于測試,每一個類都繼承了主窗口類JFRAME,使得窗口可以獨(dú)自運(yùn)行。l INSERT類設(shè)計 功能組件 6個文本域、6個標(biāo)簽、1個按鈕 功能實(shí)現(xiàn) 添加數(shù)據(jù) 實(shí)現(xiàn)過程 對按鈕添加監(jiān)
3、控,實(shí)現(xiàn)按鈕事件為獲取文本域中的信息,并執(zhí)行SQL的INSERT語句。l QUERY類設(shè)計 功能組件 5個按鈕、三個單行文本組件、1個下拉框、1個多行文本 功能實(shí)現(xiàn) 按學(xué)號查詢、按姓名查詢、按班級查詢、按課程查詢、顯示全部 實(shí)現(xiàn)過程 對按鈕添加監(jiān)控,共有五個監(jiān)控事件,前三個實(shí)現(xiàn)按鈕事件為先獲取文本域中的信息,根據(jù)對應(yīng)查詢的要求執(zhí)行相應(yīng)的SQL的SELLECT語句;按課程查詢通過在下來框中選擇對應(yīng)的選項,即查詢相應(yīng)的課程;第五個查詢按鈕將全部信息在多行文本框中輸出。l MODIFY類設(shè)計 功能組件 6個單行文本、6個標(biāo)簽、1個按鈕 功能實(shí)現(xiàn) 修改數(shù)據(jù) 實(shí)現(xiàn)過程 與添加數(shù)據(jù)類似,對按鈕添加監(jiān)控,實(shí)
4、現(xiàn)按鈕事件為獲取文本域中的信息,并執(zhí)行SQL的UPDATE語句;不同的是以學(xué)號為主鍵進(jìn)行查找并更新。l DELETE類設(shè)計 功能組件 1個單行文本、1個標(biāo)簽、1個按鈕、1個多行文本 功能實(shí)現(xiàn) 刪除數(shù)據(jù) 實(shí)現(xiàn)過程 與修改數(shù)據(jù)類似,對按鈕添加監(jiān)控,實(shí)現(xiàn)按鈕事件為獲取文本域中的學(xué)號信息,并執(zhí)行SQL的DELETE語句;不同的是以學(xué)號為主鍵進(jìn)行查找并將刪除信息輸出到文本框中。2、數(shù)據(jù)庫設(shè)計l 系統(tǒng)概念結(jié)構(gòu)設(shè)計語文 學(xué)號姓名數(shù)學(xué)成績查詢系統(tǒng)班級英語l 系統(tǒng)邏輯結(jié)構(gòu)設(shè)計學(xué)生成績信息表字段名 屬性類型空值約束條件學(xué)號ID文本not null主鍵姓名name文本從鍵班級class文本從簡語文Chinese長整
5、數(shù)英語English長整數(shù)數(shù)學(xué)Maths長整數(shù)l 數(shù)據(jù)庫截圖3、主界面設(shè)計MAINFRAME類設(shè)計 功能組件 4個按鈕、1個背景、2個標(biāo)簽文本、2個面板 功能實(shí)現(xiàn) 查詢數(shù)據(jù)、添加數(shù)據(jù)、刪除數(shù)據(jù)、修改數(shù)據(jù) 實(shí)現(xiàn)過程 對按鈕添加監(jiān)控,共有4個監(jiān)控事件,實(shí)現(xiàn)按鈕事件為創(chuàng)建對應(yīng)功能的類對象,出現(xiàn)相應(yīng)的功能窗口。三、運(yùn)行截圖 主界面 添加數(shù)據(jù) 查詢數(shù)據(jù)l 按學(xué)號查詢l 按姓名查詢l 按班級查詢l 按課程名稱查詢l 顯示所有信息 修改數(shù)據(jù) 刪除數(shù)據(jù)四、實(shí)驗(yàn)感想 通過此次課程設(shè)計我學(xué)會了很多知識,將Java課上遺漏的知識又進(jìn)一步補(bǔ)上。實(shí)踐過程中遇到了很多困難,比如沒學(xué)過數(shù)據(jù)庫,SQL語句不熟,對eclips
6、e的使用很生疏等,因此花費(fèi)了很多時間在前期準(zhǔn)備工作上。即使如此,也有一些功能尚未實(shí)現(xiàn),例如查詢優(yōu)秀率、最高分和最低分等,雖然比較簡單,但由于時間問題還是沒來得及做。由于本次試驗(yàn)的很多知識都是現(xiàn)學(xué)現(xiàn)用,以致很多地方的代碼顯得累贅繁瑣。但總體上主要功能是實(shí)現(xiàn)了的,并且美化了一下主界面。 總之,此次課程設(shè)計讓我獲益匪淺,我將會繼續(xù)把它完善做好。五、源代碼清單 MainFrame類import javax.swing.*;import java.awt.*;import java.awt.event.*;public class MainFrame extends JFrameJButton inse
7、rt,query,delete,modify;JPanel panel,panel1,panel2;public MainFrame()/ TODO Auto-generated method stubImageIcon img=new ImageIcon(1.gif);JLabel text1,text2,picture=new JLabel(img); JFrame frame=new JFrame(學(xué)生成績管理系統(tǒng)); insert=new JButton(添加數(shù)據(jù)); insert.setBackground(Color.green); insert.addActionListener
8、(new insertActionPerformed(); query=new JButton(查詢數(shù)據(jù)); query.addActionListener(new queryActionPerformed(); query.setBackground(Color.green); modify=new JButton(修改數(shù)據(jù)); modify.setBackground(Color.green); modify.addActionListener(new modifyActionPerformed(); delete=new JButton(刪除數(shù)據(jù)); delete.setBackgrou
9、nd(Color.green); delete.addActionListener(new deleteActionPerformed(); frame.setSize(360,200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane=frame.getContentPane(); contentPane.setLayout(new BorderLayout(); text1=new JLabel(歡迎使用學(xué)生成績管理系統(tǒng),JLabel.CENTER); text1.setFont(new
10、 Font(宋體,Font.BOLD,24); text1.setForeground(Color.blue); text2=new JLabel(-192091班 羅斌制作); text2.setFont(new Font(TimesRoman,Font.ROMAN_BASELINE,14); panel1=new JPanel(); panel1.add(insert); panel1.add(query); panel2=new JPanel(); panel2.add(modify); panel2.add(delete); panel1.setOpaque(false); panel
11、2.setOpaque(false); panel=new JPanel(); panel.add(text2,BorderLayout.NORTH); panel.add(panel1,BorderLayout.NORTH); panel.add(panel2,BorderLayout.SOUTH); panel.setOpaque(false); contentPane.add(text1,BorderLayout.NORTH); contentPane.add(panel,BorderLayout.CENTER); frame.getLayeredPane().add(picture,n
12、ew Integer(Integer.MIN_VALUE); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int screenWidth = screenSize.width/2; int screenHeight = screenSize.height/2; int height = this.getHeight(); int width = this.getWidth(); picture.setBounds(0,0,360,360); (JPanel)cont
13、entPane).setOpaque(false); frame.setLocation(screenWidth-width/2, screenHeight-height/2); frame.setVisible(true); public class insertActionPerformed implements ActionListener public void actionPerformed(ActionEvent e) new Insert().setVisible(true); public class modifyActionPerformed implements Actio
14、nListener public void actionPerformed(ActionEvent e) new Modify().setVisible(true); public class queryActionPerformed implements ActionListener public void actionPerformed(ActionEvent e) new Query().setVisible(true); public class deleteActionPerformed implements ActionListener public void actionPerf
15、ormed(ActionEvent e) new Delete().setVisible(true); public static void main(String args) new MainFrame(); Insert類import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;public class Insert extends JFrame JTextField input1,input2,input3,input4,input5,input6;JLabel label1,labe
16、l2,label3,label4,label5;JButton button; static Statement st; static try Class.forName(sun.jdbc.odbc.JdbcOdbcDriver); Connection con=DriverManager.getConnection(jdbc:odbc:student); st=con.createStatement(); catch(Exception e) ResultSet rs;public Insert()input1=new JTextField(15);input2=new JTextField
17、(15);input3=new JTextField(15);input4=new JTextField(15);input5=new JTextField(15);input6=new JTextField(15);JPanel panel=new JPanel();panel.setLayout(new GridLayout(6,2);panel.add(new JLabel(學(xué)號),BorderLayout.CENTER);panel.add(input1);panel.add(new JLabel(姓名),BorderLayout.CENTER);panel.add(input2);p
18、anel.add(new JLabel(班級),BorderLayout.CENTER);panel.add(input3);panel.add(new JLabel(語文),BorderLayout.CENTER);panel.add(input4);panel.add(new JLabel(英語);panel.add(input5);panel.add(new JLabel(數(shù)學(xué));panel.add(input6);button=new JButton(添加);button.addActionListener(new mysql();Container container=getCont
19、entPane();container.add(panel,BorderLayout.CENTER);container.add(button,BorderLayout.SOUTH);setTitle(添加數(shù)據(jù)窗口);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);setSize(250,250); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int screenWidth = screenSize.width/2
20、; int screenHeight = screenSize.height/2; int height = this.getHeight(); int width = this.getWidth(); setLocation(screenWidth-width/2, screenHeight-height/2);setVisible(true);class mysql implements ActionListenerpublic void actionPerformed(ActionEvent e)tryString number=input1.getText().trim();Strin
21、g name=input2.getText().trim();String clas=input3.getText().trim();String temp=input4.getText();int chinese=Integer.parseInt(temp);temp=input4.getText();int english=Integer.parseInt(temp);temp=input4.getText();int maths=Integer.parseInt(temp);if(number.equals()|name.equals()| clas.equals()|temp.equa
22、ls()JOptionPane.showMessageDialog(Insert.this,請重新輸入,提示對話框,1);elseString sql=insert into ScoreInfo(ID,name,class,Chinese,English,Maths) values(+number+,+name+,+clas+,+chinese+,+english+,+maths+); st.executeUpdate(sql); JOptionPane.showMessageDialog(Insert.this, 數(shù)據(jù)添加成功,提示對話框,1); input1.setText(); inpu
23、t2.setText(); input3.setText(); input4.setText(); input5.setText(); input6.setText();catch(Exception ee) Query類import java.awt.*;import .*;import java.awt.event.*;import javax.swing.*;import java.sql.*;public class Query extends JFrameJTextArea show;JButton button1,button2,button3,button4,button5;JT
24、extField field1,field2,field3;JComboBox comoBox;static Statement st; static try Class.forName(sun.jdbc.odbc.JdbcOdbcDriver); Connection con=DriverManager.getConnection(jdbc:odbc:student); st=con.createStatement(); catch(Exception e) public Query()show=new JTextArea(5,10);button1=new JButton(顯示所有信息);
25、button1.addActionListener(new Mysql1();Container container=getContentPane(); container.setLayout(new BorderLayout();JPanel panel=new JPanel();JPanel mainpanel=new JPanel();button2=new JButton(按學(xué)號查詢);button2.addActionListener(new Mysql2();panel.add(button2);field1=new JTextField(7);panel.add(field1);
26、panel.setVisible(true);mainpanel.add(panel);button3=new JButton(按姓名查詢);button3.addActionListener(new Mysql3();panel.add(button3);field2=new JTextField(6);panel.add(field2);panel.setVisible(true);mainpanel.add(panel);button4=new JButton(按班級查詢);button4.addActionListener(new Mysql4();panel.add(button4)
27、;field3=new JTextField(6);panel.add(field3);panel.setVisible(true);mainpanel.add(panel);String items=請選擇,語文,英語,數(shù)學(xué);comoBox=new JComboBox(items);button5=new JButton(按課程名稱查詢);button5.addActionListener(new Mysql5();panel.add(button5);panel.add(comoBox);panel.setVisible(true);mainpanel.add(panel);panel=n
28、ew JPanel();panel.add(button1);container.add(mainpanel,BorderLayout.NORTH);container.add(panel,BorderLayout.SOUTH);container.add(new JScrollPane(show),BorderLayout.CENTER);setTitle(查詢數(shù)據(jù));setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);setSize(750,400); Toolkit kit = Toolkit.getDefaultToolkit(); Di
29、mension screenSize = kit.getScreenSize(); int screenWidth = screenSize.width/2; int screenHeight = screenSize.height/2; int height = this.getHeight(); int width = this.getWidth(); setLocation(screenWidth-width/2, screenHeight-height/2);setVisible(true);class Mysql1 implements ActionListenerpublic vo
30、id actionPerformed(ActionEvent e)tryString sql=select * from ScoreInfo;ResultSet rs=st.executeQuery(sql);show.setText();show.append(序號 學(xué)號 姓名 班級 語文 英語 數(shù)學(xué)+n);while(rs.next()show.append(rs.getInt(1)+ );show.append(rs.getString(2)+ );show.append(rs.getString(3)+ );show.append(rs.getString(4)+ );show.app
31、end(rs.getInt(5)+ );show.append(rs.getInt(6)+ );show.append(rs.getInt(7)+n);catch(Exception ee)class Mysql2 implements ActionListenerpublic void actionPerformed(ActionEvent e)tryString ss=field1.getText().trim();String sql=select * from ScoreInfo where ID=+ss+;ResultSet rs=st.executeQuery(sql);show.
32、setText();show.append(序號 學(xué)號 姓名 班級 語文 英語 數(shù)學(xué)+n);while(rs.next()show.append(rs.getInt(1)+ );show.append(rs.getString(2)+ );show.append(rs.getString(3)+ );show.append(rs.getString(4)+ );show.append(rs.getInt(5)+ );show.append(rs.getInt(6)+ );show.append(rs.getInt(7)+n);catch(Exception ee)class Mysql3 im
33、plements ActionListenerpublic void actionPerformed(ActionEvent e)tryString ss=field2.getText().trim();String sql=select * from ScoreInfo where name=+ss+;ResultSet rs=st.executeQuery(sql);show.setText();show.append(序號 學(xué)號 姓名 班級 語文 英語 數(shù)學(xué)+n);while(rs.next()show.append(rs.getInt(1)+ );show.append(rs.getS
34、tring(2)+ );show.append(rs.getString(3)+ );show.append(rs.getString(4)+ );show.append(rs.getInt(5)+ );show.append(rs.getInt(6)+ );show.append(rs.getInt(7)+n);catch(Exception ee)class Mysql4 implements ActionListenerpublic void actionPerformed(ActionEvent e)tryString ss=field3.getText().trim();String
35、 sql=select * from ScoreInfo where class=+ss+;ResultSet rs=st.executeQuery(sql);show.setText();show.append(序號 學(xué)號 姓名 班級 語文 英語 數(shù)學(xué)+n);while(rs.next()show.append(rs.getInt(1)+ );show.append(rs.getString(2)+ );show.append(rs.getString(3)+ );show.append(rs.getString(4)+ );show.append(rs.getInt(5)+ );show.
36、append(rs.getInt(6)+ );show.append(rs.getInt(7)+n);catch(Exception ee)class Mysql5 implements ActionListenerpublic void actionPerformed(ActionEvent e)tryString sql=;String ss=comoBox.getSelectedItem().toString();if(ss.equals(語文)sql=select ID,name,class,Chinese from ScoreInfo ;show.setText();show.app
37、end(序號 學(xué)號 姓名 班級 語文+n);else if(ss.equals(英語)sql=select ID,name,class,English from ScoreInfo ;show.setText();show.append(序號 學(xué)號 姓名 班級 英語 +n);else if(ss.equals(數(shù)學(xué))sql=select ID,name,class,Maths from ScoreInfo ;show.setText();show.append(序號 學(xué)號 姓名 班級 數(shù)學(xué)+n);ResultSet rs=st.executeQuery(sql);int i=0;while(r
38、s.next()i+;show.append(+i+ +rs.getString(1)+ );show.append(rs.getString(2)+ );show.append(rs.getString(3)+ );show.append(rs.getInt(4)+n);catch(Exception ee) Modify類import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;public class Modify extends JFrameJTextField input1,inp
39、ut2,input3,input4,input5,input6;JLabel label1,label2,label3,label4,label5;JButton button; static Statement st; static try Class.forName(sun.jdbc.odbc.JdbcOdbcDriver); Connection con=DriverManager.getConnection(jdbc:odbc:student); st=con.createStatement(); catch(Exception e) ResultSet rs;public Modif
40、y()input1=new JTextField(15);input2=new JTextField(15);input3=new JTextField(15);input4=new JTextField(15);input5=new JTextField(15);input6=new JTextField(15);JPanel panel=new JPanel();panel.setLayout(new GridLayout(6,2);panel.add(new JLabel(學(xué)號);panel.add(input1);panel.add(new JLabel(姓名);panel.add(i
41、nput2);panel.add(new JLabel(班級);panel.add(input3);panel.add(new JLabel(語文);panel.add(input4);panel.add(new JLabel(英語);panel.add(input5);panel.add(new JLabel(數(shù)學(xué));panel.add(input6);button=new JButton(修改);button.addActionListener(new mysql();Container container=getContentPane();container.add(panel,Bord
42、erLayout.CENTER);container.add(button,BorderLayout.SOUTH);setTitle(修改數(shù)據(jù)窗口);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);setSize(300,150); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int screenWidth = screenSize.width/2; int screenHeight = screenSize.he
43、ight/2; int height = this.getHeight(); int width = this.getWidth(); setLocation(screenWidth-width/2, screenHeight-height/2);setVisible(true);class mysql implements ActionListenerpublic void actionPerformed(ActionEvent e)tryString number=input1.getText().trim();String name=input2.getText().trim();Str
44、ing clas=input3.getText().trim();String temp=input4.getText();int chinese=Integer.parseInt(temp);temp=input4.getText();int english=Integer.parseInt(temp);temp=input4.getText();int maths=Integer.parseInt(temp);if(number.equals()JOptionPane.showMessageDialog(Modify.this,學(xué)號不能為空!,提示對話框,1);elsetryString sql=update ScoreInfo set name=
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030年中國移動餐飲行業(yè)市場深度調(diào)研及競爭格局與投資研究報告
- 2025-2030年中國電梯檢驗(yàn)檢測行業(yè)應(yīng)用趨勢及投資戰(zhàn)略規(guī)劃報告
- 2025-2030年中國電子數(shù)據(jù)交換軟件行業(yè)市場現(xiàn)狀供需分析及投資評估規(guī)劃分析研究報告
- 2025-2030年中國電子中的可拉伸導(dǎo)體行業(yè)市場現(xiàn)狀供需分析及投資評估規(guī)劃分析研究報告
- 2025-2030年中國電動自行車市場深度調(diào)研及發(fā)展策略研究報告
- 2025-2030年中國電動工具配件行業(yè)市場現(xiàn)狀供需分析及投資評估規(guī)劃分析研究報告
- 2025-2030年中國甲基睪酮行業(yè)市場現(xiàn)狀供需分析及投資評估規(guī)劃分析研究報告
- 2025-2030年中國環(huán)境衛(wèi)生管理行業(yè)市場現(xiàn)狀供需分析及投資評估規(guī)劃分析研究報告
- 2025-2030年中國貓飼糧行業(yè)市場發(fā)展分析及發(fā)展趨勢與投資前景研究報告
- 2025-2030年中國牲畜脫毛機(jī)行業(yè)市場現(xiàn)狀供需分析及投資評估規(guī)劃分析研究報告
- 2025年湖北荊州市監(jiān)利市暢惠交通投資有限公司招聘筆試參考題庫含答案解析
- 酒店入股合同協(xié)議書
- 2025-2030中國無煙原煤行業(yè)市場現(xiàn)狀供需分析及市場深度研究發(fā)展前景及規(guī)劃可行性分析研究報告
- GB/T 32960.3-2025電動汽車遠(yuǎn)程服務(wù)與管理系統(tǒng)技術(shù)規(guī)范第3部分:通信協(xié)議及數(shù)據(jù)格式
- 2024年江蘇省勞動關(guān)系研究院招聘考試真題
- 2024年四川省公安廳招聘警務(wù)輔助人員真題
- 突發(fā)性聾診療指南(2025版)
- 2025年電子信息工程師職業(yè)資格考試試卷及答案
- 糧食局業(yè)務(wù)知識課件
- 小學(xué)科學(xué)青島版 (五四制2017)五年級下冊26 探索宇宙教案
- 2025年廣東松山職業(yè)技術(shù)學(xué)院單招職業(yè)傾向性測試題庫
評論
0/150
提交評論