




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、精選優質文檔-傾情為你奉上Java課程設計-簡單的班級管理系統學院:船山學院 班級:計算機029班姓名: 陳 強 學號: 2004-12-20一:需求分析1.功能需求1).能夠實現對班級學生基本資料的錄入,包括學生的學號,姓名,性別,所學專業,家庭住址以及出生年月等。2).能夠實現對學生基本資料的修改。3).根據學號對學生資料進行查詢。4).能夠刪除某些學生的資料。二:總體設計 本班級管理系統共有6個java源文件。類之間的主要關系如下圖所示: StudentManager(主類)DeleteStudentStudentSituationModiifySituationInquest各主類的主
2、要作用如下:1).StudentManager.java該java文件的類負責創建班級學生管理系統的主窗口。該類包含main方法,程序從該類開始執行。2).StudentStituation.java該文件的類負責創建班級學生管理系統的學生信息錄入界面。3).ModifySituation.java該文件的類負責創建班級學生管理系統的學生基本信息修改界面。4).Inquest.java該文件的類負責創建班級學生管理系統的學生基本信息查詢界面。5).Delete.java該文件的類負責創建班級學生管理系統的學生信息刪除界面。6).Student.java負責創建存放學生信息的對象。三:詳細設計1
3、 主類StudentManager.java1).成員變量主要成員變量成員變量描述變量類型變量名稱基本信息錄入界面基本信息修改界面基本信息查詢界面基本信息刪除界面菜單選項 存基本信息的散列表存放散列表的文件StudentSituationModifySituationInquestDeleteJMenuItemHashtableFile基本信息錄入基本信息修改基本信息查詢基本信息刪除錄入,修改,查詢,刪除基本信息file2).方法主要方法名稱功能備注StudentManageractionPerformedmain創建程序主窗口 處理ActionEvent事件程序開始運行構造方法接口方法3).
4、代碼StudentManager.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.Hashtable;public class StudentManager extends JFrame implements ActionListener StudentSituation 基本信息錄入=null; ModifySituation 基本信息修改=null; Inquest 基本信息查詢=null; Delete 基本信息刪除=null; JMe
5、nuBar bar; JMenu fileMenu; JMenuItem 錄入,修改,查詢,刪除,退出; Container con=null; Hashtable 基本信息=null; File file=null; CardLayout card=null; JLabel label; JPanel pCenter; public StudentManager() setTitle("歡迎進入班級管理系統"); 錄入=new JMenuItem("錄入學生基本信息"); 修改=new JMenuItem("修改學生基本信息");
6、查詢=new JMenuItem("查詢學生基本信息"); 刪除=new JMenuItem("刪除學生基本信息"); 退出=new JMenuItem("退出本系統"); 退出.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) System.exit(0); ); bar=new JMenuBar(); fileMenu=new JMenu("菜單選項"); fileMenu.add(錄入);
7、 fileMenu.addSeparator(); fileMenu.add(修改); fileMenu.addSeparator(); fileMenu.add(查詢); fileMenu.addSeparator(); fileMenu.add(刪除); fileMenu.addSeparator(); fileMenu.addSeparator(); fileMenu.add(退出); bar.add(fileMenu); setJMenuBar(bar); label=new JLabel("歡迎進入班級管理系統!",label.CENTER); label.set
8、Font(new Font("隸書",Font.BOLD,30); label.setForeground(Color.blue); 基本信息=new Hashtable(); 錄入.addActionListener(this); 修改.addActionListener(this); 查詢.addActionListener(this); 刪除.addActionListener(this); card=new CardLayout(); con=getContentPane(); pCenter=new JPanel(); pCenter.setLayout(card
9、); file=new File("學生基本信息.txt"); if(!file.exists() try FileOutputStream out=new FileOutputStream(file); ObjectOutputStreamobjectOut=new ObjectOutputStream(out); objectOut.writeObject(基本信息); objectOut.close(); out.close(); catch(IOException e) 基本信息錄入=new StudentSituation(file); 基本信息修改=new Mo
10、difySituation(file); 基本信息查詢=new Inquest(this,file); 基本信息刪除=new Delete(file); pCenter.add("歡迎語界面",label); pCenter.add("錄入界面",基本信息錄入); pCenter.add("修改界面",基本信息修改); pCenter.add("刪除界面",基本信息刪除); con.add(pCenter,BorderLayout.CENTER); con.validate(); addWindowListener
11、(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); setVisible(true); setBounds(100,50,420,380); validate(); public void actionPerformed(ActionEvent e) if(e.getSource()=錄入) card.show(pCenter,"錄入界面"); else if(e.getSource()=修改) card.show(pCenter,"修改界面")
12、; else if(e.getSource()=查詢) 基本信息查詢.setVisible(true); else if(e.getSource()=刪除) card.show(pCenter,"刪除界面"); public static void main(String args) new StudentManager(); 2.錄入界面1).成員變量主要成員變量屬性描述變量類型變量名稱存放“學生”對象的散列表輸入學生基本信息的文本存放學生信息的對象HashtableJTextFieldStudent基本信息表學號,姓名,所學專業,家庭住址,出生學生2).方法主要方法名稱
13、功能備注StudentSituationactionPerformed創建學生信息錄入界面處理ActionEvent事件構造方法接口方法3).代碼StudentSituation.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class StudentSituation extends JPanel implements ActionListener Hashtable 基本信息表=null; JTextField 學號,
14、姓名,所學專業,家庭住址,出生; JRadioButton 男,女; Student 學生=null; ButtonGroup group=null; JButton 錄入,重置; FileInputStream inOne=null; ObjectInputStream inTwo=null; FileOutputStream outOne=null; ObjectOutputStream outTwo=null; File file=null; public StudentSituation(File file) this.file=file; 學號=new JTextField(10);
15、 姓名=new JTextField(10); 所學專業=new JTextField(10); 家庭住址=new JTextField(10); 出生=new JTextField(10); group=new ButtonGroup(); 男=new JRadioButton("男",true); 女=new JRadioButton("女",false); group.add(男); group.add(女); 錄入=new JButton("錄入"); 重置=new JButton("重置"); 錄入.ad
16、dActionListener(this); 重置.addActionListener(this); Box box1=Box.createHorizontalBox(); box1.add(new JLabel("學號:",JLabel.CENTER); box1.add(學號); Box box2=Box.createHorizontalBox(); box2.add(new JLabel("姓名:",JLabel.CENTER); box2.add(姓名); Box box3=Box.createHorizontalBox(); box3.add(
17、new JLabel("性別:",JLabel.CENTER); box3.add(男); box3.add(女); Box box4=Box.createHorizontalBox(); box4.add(new JLabel("所學專業:",JLabel.CENTER); box4.add(所學專業); Box box5=Box.createHorizontalBox(); box5.add(new JLabel("家庭住址:",JLabel.CENTER); box5.add(家庭住址); Box box6=Box.create
18、HorizontalBox(); box6.add(new JLabel("出生:",JLabel.CENTER); box6.add(出生); Box boxH=Box.createVerticalBox(); boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(box5); boxH.add(box6); boxH.add(Box.createVerticalGlue(); JPanel pCenter=new JPanel(); pCenter.add(boxH); setL
19、ayout(new BorderLayout(); add(pCenter,BorderLayout.CENTER); JPanel pSouth=new JPanel(); pSouth.add(錄入); pSouth.add(重置); add(pSouth,BorderLayout.SOUTH); validate(); public void actionPerformed(ActionEvent e) if(e.getSource()=錄入) String number="" number=學號.getText(); if(number.length()>0)
20、 try inOne=new FileInputStream(file); inTwo=new ObjectInputStream(inOne); 基本信息表=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); catch(Exception ee) if(基本信息表.containsKey(number) String warning="該生基本信息已存在,請到修改頁面修改!" JOptionPane.showMessageDialog(this,warning,警告",JOptionPane
21、.WARNING_MESSAGE); else String m="基本信息將被錄入!" intok=JOptionPane.showConfirmDialog(this,m,"確認",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE); if(ok=JOptionPane.YES_OPTION) String name=姓名.getText(); String discipling=所學專業.getText(); String grade=家庭住址.getText(); String b
22、orth=出生.getText(); String sex=null; if(男.isSelected() sex=男.getText(); else sex=女.getText(); 學生=new Student(); 學生.setNumber(number); 學生.setName(name); 學生.setDiscipling(discipling); 學生.setGrade(grade); 學生.setBorth(borth); 學生.setSex(sex); try outOne=new FileOutputStream(file); outTwo=new ObjectOutputS
23、tream(outOne); 基本信息表.put(number,學生); outTwo.writeObject(基本信息表); outTwo.close(); outOne.close(); 學號.setText(null); 姓名.setText(null); 所學專業.setText(null); 家庭住址.setText(null); 出生.setText(null); catch(Exception ee) System.out.println(ee); else String warning="必須要輸入學號!" JOptionPane.showMessageDi
24、alog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); if(e.getSource()=重置) 學號.setText(null); 姓名.setText(null); 所學專業.setText(null); 家庭住址.setText(null); 出生.setText(null); 3.查詢界面1).成員變量主要成員變量屬性描述變量類型變量名稱存放“學生”對象的散表顯示學生基本信息的文本HashtableJTextField基本信息表學號,姓名,所學專業,家庭住址,出生2).方法主要方法名稱功能備注Inquestactio
25、nPerformed創建查詢界面處理ActionEvent事件構造方法接口方法3).代碼Inquest.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class Inquest extends JDialog implements ActionListener Hashtable 基本信息表=null; JTextField 學號,姓名,所學專業,家庭住址,出生; JRadioButton 男,女; JButton 查詢;
26、 ButtonGroup group=null; FileInputStream inOne=null; ObjectInputStream inTwo=null; File file=null; public Inquest(JFrame f,File file) super(f,"查詢對話框",false); this.file=file; 學號=new JTextField(10); 查詢=new JButton("查詢"); 學號.addActionListener(this); 查詢.addActionListener(this); 姓名=ne
27、w JTextField(10); 姓名.setEditable(false); 所學專業=new JTextField(10); 所學專業.setEditable(false); 家庭住址=new JTextField(10); 家庭住址.setEditable(false); 出生=new JTextField(10); 出生.setEditable(false); 男=new JRadioButton("男",false); 女=new JRadioButton("女",false); group=new ButtonGroup(); group.
28、add(男); group.add(女); Box box1=Box.createHorizontalBox(); box1.add(new JLabel("輸入要查詢的學號:",JLabel.CENTER); box1.add(學號); box1.add(查詢); Box box2=Box.createHorizontalBox(); box2.add(new JLabel("姓名:",JLabel.CENTER); box2.add(姓名); Box box3=Box.createHorizontalBox(); box3.add(new JLabe
29、l("性別:",JLabel.CENTER); box3.add(男); box3.add(女); Box box4=Box.createHorizontalBox(); box4.add(new JLabel("所學專業:",JLabel.CENTER); box4.add(所學專業); Box box5=Box.createHorizontalBox(); box5.add(new JLabel("家庭住址:",JLabel.CENTER); box5.add(家庭住址); Box box6=Box.createHorizonta
30、lBox(); box6.add(new JLabel("出生:",JLabel.CENTER); box6.add(出生); Box boxH=Box.createVerticalBox(); boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(box5); boxH.add(box6); boxH.add(Box.createVerticalGlue(); JPanel pCenter=new JPanel(); pCenter.add(boxH); Container con
31、=getContentPane(); con.add(pCenter,BorderLayout.CENTER); con.validate(); setVisible(false); setBounds(100,200,360,270); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) setVisible(false); ); public void actionPerformed(ActionEvent e) 姓名.setText(null); 所學專業.setText(null)
32、; 家庭住址.setText(null); 出生.setText(null); if(e.getSource()=查詢|e.getSource()=學號) String number="" number=學號.getText(); if(number.length()>0) try inOne=new FileInputStream(file); inTwo=new ObjectInputStream(inOne); 基本信息表=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); catch(Exc
33、eption ee) if(基本信息表.containsKey(number) Student stu=(Student)基本信息表.get(number); 姓名.setText(stu.getName(); 所學專業.setText(stu.getDisciping(); 家庭住址.setText(stu.getGrade(); 出生.setText(stu.getBorth(); if(stu.getSex().equals("男") 男.setSelected(true); else 女.setSelected(true); else String warning=
34、"該學號不存在!" JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); else String warning="必須要輸入學號!" JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); 3.修改界面1).成員變量主要成員變量描述變量類型變量名稱存放“學生”對象的散列表輸入學生基本信息的文本條HashtabelJ
35、TextField基本信息表學號,姓名,所學專業,家庭住址,出生2).方法主要方法名稱功能備注ModifySituationactionPerform創建學生信息修改界面處理ActionEvent事件構造方法接口方法3).代碼ModifySituation.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class ModifySituation extends JPanel implements ActionListene
36、r Hashtable 基本信息表=null; JTextField 學號,姓名,所學專業,家庭住址,出生; JRadioButton 男,女; ButtonGroup group=null; JButton 開始修改,錄入修改,重置; FileInputStream inOne=null; ObjectInputStream inTwo=null; FileOutputStream outOne=null; ObjectOutputStream outTwo=null; File file=null; public ModifySituation(File file) this.file=f
37、ile; 學號=new JTextField(10); 姓名=new JTextField(10); 所學專業=new JTextField(10); 家庭住址=new JTextField(10); 出生=new JTextField(10); group=new ButtonGroup(); 男=new JRadioButton("男",true); 女=new JRadioButton("女",false); group.add(男); group.add(女); 開始修改=new JButton("開始修改"); 錄入修改=n
38、ew JButton("錄入修改"); 錄入修改.setEnabled(false); 重置=new JButton("重置"); 學號.addActionListener(this); 開始修改.addActionListener(this); 錄入修改.addActionListener(this); 重置.addActionListener(this); Box box1=Box.createHorizontalBox(); box1.add(new JLabel("輸入要修改信息的學號:",JLabel.CENTER); bo
39、x1.add(學號); box1.add(開始修改); Box box2=Box.createHorizontalBox(); box2.add(new JLabel("(新)姓名:",JLabel.CENTER); box2.add(姓名); Box box3=Box.createHorizontalBox(); box3.add(new JLabel("(新)性別:",JLabel.CENTER); box3.add(男); box3.add(女); Box box4=Box.createHorizontalBox(); box4.add(new J
40、Label("(新)所學專業:",JLabel.CENTER); box4.add(所學專業); Box box5=Box.createHorizontalBox(); box5.add(new JLabel("(新)家庭住址:",JLabel.CENTER); box5.add(家庭住址); Box box6=Box.createHorizontalBox(); box6.add(new JLabel("(新)出生:",JLabel.CENTER); box6.add(出生); Box boxH=Box.createVertical
41、Box(); boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(box5); boxH.add(box6); boxH.add(Box.createVerticalGlue(); JPanel pCenter=new JPanel(); pCenter.add(boxH); setLayout(new BorderLayout(); add(pCenter,BorderLayout.CENTER); JPanel pSouth=new JPanel(); pSouth.add(錄入修改); pSouth.add(重置); add(pSouth,BorderLayout.SOU
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- DB31/T 1237-2020空壓機系統運行能效評估技術規范
- DB31/T 1205-2020醫務社會工作基本服務規范
- DB31/T 1092-2018裝配式建筑混凝土預制構件單位產品能源消耗技術要求
- DB31/T 1061-2017室內裝飾裝修材料揮發性有機污染物散發率測試及評價方法
- DB31/T 1043-2017暴雨強度公式與設計雨型標準
- DB31/T 1023-2016老年宜居社區建設細則
- DB31/ 738-2020集成電路封裝單位產品能源消耗限額
- 輪胎行業可持續發展戰略考核試卷
- 南陽市桐柏縣2025年八年級《語文》上學期期末試題與參考答案
- 計算機二級Web考試重點難點試題及答案
- 幼兒園大班科學《痕跡》
- 靜脈用藥安全輸注藥護專家指引
- DB61T1755-2023放心消費示范創建認定與管理規范
- 企業借款申請書
- 乙醇管施工方案
- 項目七 信息素養與社會責任
- 電氣施工安全技術交底記錄范本
- 說課稿【全國一等獎】
- 急性扁桃體炎臨床診療指南
- 第七講 社會主義現代化建設的教育科技人才戰略PPT習概論2023優化版教學課件
- 室間質評記錄表
評論
0/150
提交評論