Java大作業(yè)簡單的學籍管理系統(tǒng)_第1頁
Java大作業(yè)簡單的學籍管理系統(tǒng)_第2頁
Java大作業(yè)簡單的學籍管理系統(tǒng)_第3頁
Java大作業(yè)簡單的學籍管理系統(tǒng)_第4頁
Java大作業(yè)簡單的學籍管理系統(tǒng)_第5頁
已閱讀5頁,還剩23頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上上海電力學院期末作業(yè):簡單的學籍管理系統(tǒng)課程:Web應用程序設計院系:電氣工程學院專業(yè):電力系統(tǒng)及其自動化學生姓名:張富杰學號: 指導教師:曹渝昆2017 年 1月6日專心-專注-專業(yè)目錄一、設計思路3二具體實現(xiàn)3三運行調(diào)試與分析3四設計體會與小結(jié)8五程序代碼8一、設計思路隨著社會經(jīng)濟的發(fā)展, 入學的同學越來越多, 為方便對同學學籍信息的的管理,設計學籍管理軟件來管理本班級同學的學籍信息。 該軟件應支持添加、刪除、修改、查詢功能。查詢方式主要是支持學號查詢,例如:輸入“1”,則顯示該學生的信息。運用流式、卡片、整體布局方式對系統(tǒng)的主界面和各功能界面進行設計; 通過連接

2、數(shù)據(jù)庫的方式來實現(xiàn)對數(shù)據(jù)的存儲; 各功能實現(xiàn)時訪問數(shù)據(jù)庫, 并對數(shù)據(jù)信息進行讀取,運用 Java 語句對其進行輸出,學號查詢時顯示在文本框中;系統(tǒng)提示功能用來提醒用戶的錯誤操作和輸入時的錯誤信息,提醒用戶進行改正。二具體實現(xiàn)1 向班級里插入一個學生,但必須是插在已經(jīng)建立的班級里。2 輸入學生信息,建立一個班級。3 修改一個學生的所有資料。4 刪除某班的一個學生及其所有資料。5 刪除一個班級。6根據(jù)學生姓名查找某個學生信息。每種功能通過一個類來實現(xiàn):類分分為主類、查詢類、修改類、添加類、增加類。主類各功能界面的連接;精確查詢類 (SearchStudent)實現(xiàn)根據(jù)學生姓名查找某個學生信息;修改

3、類 (MdifyStudent) 實現(xiàn)修改一個學生的所有資料;添加類(AddStudent)實現(xiàn)向班級里插入一個學生,但必須是插在已經(jīng)建立的班級里。 ;刪除類 (DeleteStudent)實現(xiàn)刪除某班的一個學生及其所有資料。 ;刪除類 (DeleteClass) 實現(xiàn)刪除一個班級;建立類( BuiltClass)實現(xiàn)輸入學生信息建立一個班級。三運行調(diào)試與分析系統(tǒng)的詳細設計代碼請查閱附帶的代碼。以下僅對各個界面進行截圖展示:圖 1:管理界面圖 2:添加學生到指定的班級界面圖 3:刪除一個學生信息界面圖 4:修改一個學生信息界面圖 5:查詢某個學生信息界面圖 6 刪除一個班級界面圖 7:輸入一個

4、學生建立一個班級界面運行 JAVA程序中的 StudentManager 文件,顯示系統(tǒng)的主界面,如圖 1 所示,主界面有進入其他子功能的按鈕, 選擇相應的按鈕便可進入相應的功能。 添加學生到指定班級功能如圖 2 所示,根據(jù)提示輸入要添加的信息, 點擊確定, 將彈出提示框,確認是否添加。 輸入一個學生建立一個班級功能如圖 7 所示,根據(jù)提示輸入要添加的信息,點擊確定,將彈出提示框,確認是否建立。刪除一個班級信息功能如圖 6 所示,根據(jù)提示輸入班級號, 點擊刪除。刪除一個學生信息功能如圖 3 所示,根據(jù)提示輸入學號,點擊刪除。修改一個學生信息功能如圖4 所示,首先輸入要修改的人姓名, 點擊開始修

5、改, 在下面的文本框現(xiàn)實當前數(shù)據(jù)庫內(nèi)所存該人的信息,同時錄入修改鍵變化為可點擊,在文本框內(nèi)輸入要修改的學號,點擊錄入修改, 系統(tǒng)將新信息錄如數(shù)據(jù)庫。點擊查詢某個學生信息按鈕,將彈出查詢對話框, 輸入姓名便可以精確查詢到此人的所有學籍信息。查詢?nèi)鐖D 5 所示,將顯示數(shù)據(jù)庫中所存的所有號碼信息。四設計體會與小結(jié)期末大作業(yè)的課設,自己通過查找資料、復習課本、編程調(diào)試,寫實驗報告等環(huán)節(jié),進一步掌握了以前學到的知識, 并且還對 GUI組鍵的應用有了更深入的認識與掌握,另外還學到了一些新東西,比如 JAVA 的 SWING、AWT 包,以前是沒有接觸過的, 可是通過這次課程設計使得我們對這個包更了解。 通

6、過與數(shù)據(jù)庫的連接掌握了 Java與數(shù)據(jù)庫的連接技術(shù)。通過實踐的學習,我認到學好計算機要重視實踐操作,不僅僅是學習語言,還是其它的語言, 以及其它的計算機方面的知識都要重在實踐,學習過程中,我會更加注視實踐操作,使自己便好地學好計算機。java所以后在五程序代碼package simplebighomework;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class StudentManager extends JFrame implements ActionLis

7、tener / 繼承JFrame類JMenuBar jmb;/ 菜單欄JMenu Message;/ 菜單JMenuItem Item1,Item2,Item3,Item4,Item5,Item6;/ 菜單項public StudentManager(String s) / 構(gòu)造函數(shù)StudentManage/ 添加按鍵jmb = new JMenuBar();Message = new JMenu("學生信息 ");Item1 = new JMenuItem("增加學生信息到指定班級");/ 菜單名Item2 = new JMenuItem("

8、;刪除一個學生學籍信息 ");Item3 = new JMenuItem("修改一個學生信息 ");Item4 = new JMenuItem("查詢某個學生信息 ");Item5 = new JMenuItem("刪除一個班級信息 ");Item6 = new JMenuItem("輸入一個學生建立一個班級");Message.add(Item1);Message.add(Item2);Message.add(Item3);Message.add(Item4);Message.add(Item5);Me

9、ssage.add(Item6);jmb.add(Message);Item1.addActionListener(this);Item2.addActionListener(this);Item3.addActionListener(this);Item4.addActionListener(this);Item5.addActionListener(this);Item6.addActionListener(this);setTitle(s);/ 設置窗口標題setBounds(500,300,500,500); /窗口的位置setVisible(true);/ 組件可見setJMenuB

10、ar(jmb);validate();/ 菜單欄/ 再次布置容器及其組件setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/設置隱藏,關(guān)閉,放大窗口public void actionPerformed(ActionEvent e)/ActionEvent 包含一個事件,該事件為執(zhí)行動作事件點擊按鈕等if (e.getSource() = Item1) /e.getSource() = Item2)返回的當前動作所指向的對象,包含對象的所有信息。AddStudent ad = new AddStudent(); else if (e.getSourc

11、e() = Item2) / 通過獲取事件源, 獲取相應的對象DeleteStudent ds = new DeleteStudent(); else if (e.getSource() = Item3) ModifyStudent ms = new ModifyStudent(); else if (e.getSource() = Item4) SearchStudent ss = new SearchStudent(); else if (e.getSource() = Item5) DeleteClass dc = new DeleteClass(); else if (e.getSou

12、rce() = Item6) BuiltClassbc = new BuiltClass();public static void main(String args) StudentManager stu=new StudentManager("學生管理系統(tǒng) ");package simplebighomework;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class AddStudent extends JFrame implements

13、ActionListener /繼承 java的窗口體類JLabel JL = new JLabel("添加學生到指定班級 ", JLabel.CENTER);JLabel JLNumber = new JLabel("學號 :");/ 顯示輸入學號JTextField JTNumber = new JTextField(); / 創(chuàng)建文本框JLabel JLName = new JLabel("姓名 :");JTextField JTName = new JTextField();JLabel JLClass = new JLabe

14、l("班級 :");ButtonGroup BG = new ButtonGroup();JRadioButton JRB1 = new JRadioButton("一班 ");JRadioButton JRB2 = new JRadioButton("二班 ");JButton JBAdd = new JButton("添加 "); JButton JBExit = new JButton("退出 ");/ 創(chuàng)建按鈕public AddStudent() this.setTitle("

15、;添加學生到指定班級 ");this.setLayout(null);JL.setBounds(100, 30, 200, 40);this.add(JL);JLNumber.setBounds(140, 80, 100, 20);/x軸和y 軸,寬高this.add(JLNumber);JTNumber.setBounds(180, 80, 80, 20);this.add(JTNumber);JLName.setBounds(140, 120, 60, 20);this.add(JLName);JTName.setBounds(180, 120, 80, 20);this.add

16、(JTName);JLClass.setBounds(140, 160, 100, 20);this.add(JLClass);JRB1.setBounds(180, 160, 60, 20);JRB2.setBounds(240, 160, 60, 20);this.add(JRB1);this.add(JRB2);BG.add(JRB1);BG.add(JRB2);JBAdd.setBounds(120, 220, 60, 20);this.add(JBAdd);JBAdd.addActionListener(this);JBExit.setBounds(200, 220, 60, 20)

17、;this.add(JBExit);JBExit.addActionListener(this);this.setBounds(500, 300, 500, 400);this.setVisible(true);/ 添加窗口的位置public void actionPerformed(ActionEvent e) /監(jiān)聽接口if (e.getSource() = JBAdd) / 點擊建立的時候生效String snumber = JTNumber.getText();/ 獲取文本框中的信息String sname = JTName.getText();String sclass = 一&qu

18、ot;班 "if (JRB1.isSelected()/ 單選按鈕sclass = 一"班 "elsesclass = 二"班 "Connection con;/ 聲明 Connection 對象String driver = "com.mysql.jdbc.Driver"/ 驅(qū)動程序名/ 遍歷查詢結(jié)果集try Class.forName(driver);/ 加載驅(qū)動程序con=DriverManager.getConnection("jdbc:mysql:/localhost:3306/database?useU

19、nicode=t rue&characterEncoding=utf-8&useSSL=false","root","zfj"); /1.getConnection() 方法,連接 MySQL數(shù)據(jù)庫!Statement statement = con.createStatement(); /2. 創(chuàng)建 statement 類對象,用來執(zhí)行 SQL語句!String sql = "select * from student where id='"+snumber+"'"/ 要

20、執(zhí)行的 SQL語句ResultSet rs = statement.executeQuery(sql);/3.ResultSet類,用來存放獲取的結(jié)果集! !if (rs.next()JOptionPane.showMessageDialog(null,"該號已經(jīng)存在 ");/提示else sql = "insert into student values('" + snumber + "','"+ sname + "','" + sclass +"')&q

21、uot;int i = statement.executeUpdate(sql);/ 執(zhí)行SQL語句,把返回值賦給iif (i > 0)JOptionPane.showMessageDialog(null, " 建立成功 ");/ 提示成功elseJOptionPane.showMessageDialog(null, " 添加失敗 ");/ 提示失敗catch (Exception ee) / 捕獲異常if (e.getSource() = JBExit) / 退出按鈕監(jiān)視setVisible(false);public static void m

22、ain(String args) new BuiltClass();package simplebighomework;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class BuiltClass extends JFrame implements ActionListener JLabel JL = new JLabel("輸入一個學生建立一個班級", JLabel.CENTER);/什么意思JLabel JLNumber = new JLa

23、bel("學號 :");/ 顯示輸入學號JTextField JTNumber = new JTextField();/ 創(chuàng)建文本框JLabel JLName = new JLabel("姓名 :");JTextField JTName = new JTextField();JLabel JLClass = new JLabel("班級 :");JTextField JTClass = new JTextField();JButton JBAdd = new JButton("建立 ");/ 創(chuàng)建按鈕JButton

24、 JBExit = new JButton("退出 ");/ 什么意思public BuiltClass() this.setTitle("輸入一個學生建立一個班級");this.setLayout(null);JL.setBounds(100, 30, 200, 40);this.add(JL);JLNumber.setBounds(140, 80, 100, 20); /x 軸和 y 軸,寬高 this.add(JLNumber);JTNumber.setBounds(180, 80, 80, 20);this.add(JTNumber);JLNam

25、e.setBounds(140, 120, 60, 20);this.add(JLName);JTName.setBounds(180, 120, 80, 20);this.add(JTName);JLClass.setBounds(140, 160, 100, 20);this.add(JLClass);JTClass.setBounds(180, 160, 80, 20);this.add(JTClass);JBAdd.setBounds(120, 220, 60, 20);this.add(JBAdd);JBAdd.addActionListener(this);JBExit.setBo

26、unds(200, 220, 60, 20);this.add(JBExit);JBExit.addActionListener(this);this.setBounds(500, 300, 500, 400);this.setVisible(true);public void actionPerformed(ActionEvent e) if (e.getSource() = JBAdd) String snumber = JTNumber.getText();/ 什么意思?監(jiān)聽接口/ 點擊建立的時候生效/ 獲取文本框中的信息String sname = JTName.getText();S

27、tring sclass = JTClass.getText();Connection con;/ 聲明 Connection 對象String driver = "com.mysql.jdbc.Driver"/ 驅(qū)動程序名/ 遍歷查詢結(jié)果集try Class.forName(driver);/ 加載驅(qū)動程序con=DriverManager.getConnection("jdbc:mysql:/localhost:3306/database?useUnicode=t rue&characterEncoding=utf-8&useSSL=false

28、","root","zfj"); /1.getConnection() 方法,連接 MySQL數(shù)據(jù)庫!Statement statement = con.createStatement();/2.創(chuàng)建 statement 類對象,用來執(zhí)行SQL語句!Stringsql="select*fromstudentwhereid='"+snumber+"'"ResultSetrs=statement.executeQuery(sql);/3.ResultSet 類,用來存放獲取的結(jié)果集! !if

29、(rs.next()JOptionPane.showMessageDialog(null,"該號已經(jīng)存在 ");/提示else sql = "insert into student values('" + snumber + "','"+ sname + "','" + sclass +"')"int i = statement.executeUpdate(sql);/ 執(zhí)行SQL語句,把返回值賦給iif (i > 0)JOptionPane

30、.showMessageDialog(null, " 建立成功 ");/ 提示成功elseJOptionPane.showMessageDialog(null, " 添加失敗 ");/ 提示失敗catch (Exception ee) / 什么意思?if (e.getSource() = JBExit) setVisible(false);/ 什么意思?public static void main(String args) new BuiltClass();package simplebighomework;import javax.swing.*;i

31、mport java.awt.*;import java.awt.event.*;import java.sql.*;public class DeleteClass extends JFrame implements ActionListener JLabel JL = new JLabel("刪除一個班級信息 ", JLabel.CENTER); JLabel JLClass = new JLabel("班級 :"); / 顯示班級窗口 JTextField JTClass = new JTextField();輸/入班級的窗口JButton JBD

32、el = new JButton("刪除 ");JButton JBExit = new JButton("退出 ");public DeleteClass() this.setTitle("刪除一個班級信息 ");this.setLayout(null);JL.setBounds(100, 30, 200, 40);this.add(JL);JLClass.setBounds(140, 80, 60, 20);this.add(JLClass);JTClass.setBounds(180, 80, 80, 20);this.add(

33、JTClass);JBDel.setBounds(120, 120, 60, 20);this.add(JBDel);JBDel.addActionListener(this);JBExit.setBounds(200, 120, 60, 20);this.add(JBExit);JBExit.addActionListener(this);this.setBounds(500, 300, 500, 400);this.setVisible(true);public void actionPerformed(ActionEvent e)/ 執(zhí)行操作if (e.getSource() = JBD

34、el) String sclass = JTClass.getText();/ 獲取文本中輸入的班級Connection con;/ 聲明 Connection 對象String driver = "com.mysql.jdbc.Driver"/ 驅(qū)動程序名/ 遍歷查詢結(jié)果集try Class.forName(driver);/ 加載驅(qū)動程序con=DriverManager.getConnection("jdbc:mysql:/localhost:3306/database?useUnicode=true&characterEncoding=utf-8&

35、amp;useSSL=false","root","zfj");/1.getConnection() 方法,連接 MySQL數(shù)據(jù)庫!Statement statement = con.createStatement();/2.創(chuàng)建 statement 類對象,用來執(zhí)行SQL語句!Stringsql="select*fromstudentwhereclass='"+sclass+"'"ResultSetrs=statement.executeQuery(sql);/3.ResultSet 類

36、,用來存放獲取的結(jié)果集! !if (rs.next() sql = "delete from student where class='" + sclass + "'" int n = statement.executeUpdate(sql);if (n > 0)JOptionPane.showMessageDialog(null, 刪"除成功 ");elseJOptionPane.showMessageDialog(null, 刪"除失敗 "); else JOptionPane.showM

37、essageDialog(null, 不"存在該班級 ");catch (Exception er) if (e.getSource() = JBExit) setVisible(false);public static void main(String args) new DeleteClass();package simplebighomework;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class DeleteStudent exte

38、nds JFrame implements ActionListener JLabel JL = new JLabel("刪除一個學生信息 ", JLabel.CENTER);JLabel JLNumber = new JLabel("學號 :");/ 顯示輸入“學號”JTextField JTNumber = new JTextField(); /輸入學號的文本框JLabel JLClass = new JLabel("班級 :");/ 顯示輸入“班級”JTextField JTClass = new JTextField(); 輸

39、/入班級的文本框JLabel JLName = new JLabel("姓名 :");/ 顯示輸入“姓名”JTextField JTName = new JTextField(); 輸/入姓名的文本框JButton JBDel = new JButton("刪除 ");/ 刪除鍵JButton JBExit = new JButton("退出 ");/ 退出鍵public DeleteStudent() this.setTitle("刪除一個學生信息 ");this.setLayout(null);JL.setBo

40、unds(100, 30, 200, 40);this.add(JL);JLNumber.setBounds(140, 80, 100, 20);/x軸和y 軸,寬高this.add(JLNumber);JTNumber.setBounds(180, 80, 80, 20);this.add(JTNumber);JLName.setBounds(140, 120, 80, 20);/x軸和y 軸,寬高this.add(JLName);JTName.setBounds(180, 120, 80, 20);this.add(JTName);JLClass.setBounds(140, 160, 8

41、0, 20);/x軸和y 軸,寬高this.add(JLClass);JTClass.setBounds(180, 160, 80, 20);this.add(JTClass);JBDel.setBounds(120, 200, 60, 20);this.add(JBDel);JBDel.addActionListener(this);JBExit.setBounds(200, 200, 60, 20);this.add(JBExit);JBExit.addActionListener(this);this.setBounds(500, 300, 500, 400);this.setVisib

42、le(true);public void actionPerformed(ActionEvent e)if (e.getSource() = JBDel) String snumber = JTNumber.getText();/ 獲取輸入的學號Connection con;/ 聲明 Connection 對象String driver = "com.mysql.jdbc.Driver"/ 驅(qū)動程序名/ 遍歷查詢結(jié)果集try Class.forName(driver);/ 加載驅(qū)動程序con=DriverManager.getConnection("jdbc:my

43、sql:/localhost:3306/database?useUnicode=true&characterEncoding=utf-8&useSSL=false","root","zfj");Statement statement = con.createStatement();/2.創(chuàng)建 statement 類對象,用來執(zhí)行SQL語句!Stringsql="select*fromstudentwhereid='"+snumber+"'"ResultSetrs=state

44、ment.executeQuery(sql);/3.ResultSet 類,用來存放獲取的結(jié)果集! !if (rs.next() sql = "delete from student where id='" + snumber + "'" int n = statement.executeUpdate(sql); if (n > 0)JOptionPane.showMessageDialog(null," 刪除成功 ");/執(zhí)行了返回刪除成功elseJOptionPane.showMessageDialog(nu

45、ll, 刪"除失敗 ");else JOptionPane.showMessageDialog(null, 不"存在該學號學生 ");catch (Exception er) if (e.getSource() = JBExit) setVisible(false);public static void main (String args) new DeleteStudent();package simplebighomework;import javax.swing.*;import java.awt.*;import java.awt.event.*

46、;import java.sql.*;public class ModifyStudent extends JFrame implements ActionListener JLabel JL = new JLabel("修改一個學生信息 ", JLabel.CENTER);JLabel JLNumber = new JLabel("學號 :");/ 顯示學號JTextField JTNumber = new JTextField();/ 創(chuàng)建用于輸入學號的文本JLabel JLName = new JLabel("姓名 :");JT

47、extField JTName = new JTextField();JLabel JLClass = new JLabel("班級 :");JTextField JTClass = new JTextField();JButton JBGet = new JButton("修改 "); JButton JBExit = new JButton("退出 ");/ 修改按鈕public ModifyStudent() this.setTitle("修改一個學生信息 ");this.setLayout(null);JL

48、.setBounds(100, 30, 200, 40);this.add(JL);JLNumber.setBounds(140, 80, 100, 20); /x 軸和 y 軸,寬高 this.add(JLNumber);JTNumber.setBounds(180, 80, 80, 20);this.add(JTNumber);JLName.setBounds(140, 120, 60, 20);this.add(JLName);JTName.setBounds(180, 120, 80, 20);this.add(JTName);JLClass.setBounds(140, 160, 1

49、00, 20);this.add(JLClass);JTClass.setBounds(180, 160, 80, 20);this.add(JTClass);JBGet.setBounds(120, 220, 60, 20);this.add(JBGet);JBGet.addActionListener(this);JBExit.setBounds(200, 220, 60, 20);this.add(JBExit);JBExit.addActionListener(this);this.setBounds(500, 300, 500, 400);this.setVisible(true);public void actionPerformed(ActionEvent e) if (e.getSource() = JBGet) String snumber = JTNumber.getText(); / 讀取文本中輸入的學號 String sname = JTName.getText(); String sclass = JTClass.getText();Connection con;/

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論