java大作業(yè)報告模板_第1頁
java大作業(yè)報告模板_第2頁
java大作業(yè)報告模板_第3頁
java大作業(yè)報告模板_第4頁
java大作業(yè)報告模板_第5頁
已閱讀5頁,還剩17頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、鄭州輕工業(yè)學(xué)院 Java程序設(shè)計作業(yè)報告 姓名(學(xué)號)許超 (XX) 專業(yè)班級 信管13-01 指導(dǎo)教師 黃永麗 完成時間 2015 年 7月 1日 成績 一、 設(shè)計目的及任務(wù)要求設(shè)計一個簡單學(xué)生個人信息管理系統(tǒng),該系統(tǒng)具有錄入,查詢,修改三項基本功能。要求如下: (1)具有簡單的錄入,查詢和修改功能。 (2)修改學(xué)生信息必須輸入學(xué)號,然后對姓名、性別和專業(yè)等進(jìn)行修改;(3)使用集合類來保存存儲數(shù)據(jù)。(也可用文件來保存,也可以用數(shù)據(jù)庫)(4)學(xué)生個人信息必須包括:學(xué)號、姓名、性別、出生日期、身份證號、專業(yè)、班級自我簡介,其余可自行豐富。實現(xiàn)使用: 前臺窗口使用GUI編程創(chuàng)建圖形界面,對圖形界面

2、的窗口和按鈕進(jìn)行事件監(jiān)聽,對于學(xué)生信息的錄入,在GUI界面上輸入學(xué)生信息,將相應(yīng)的學(xué)生信息,保存到集合或者文件中。查詢根據(jù)查詢條件如學(xué)號把相應(yīng)的學(xué)生信息找到在圖形用戶界面上顯示出來。而修改功能是先查詢在把修改后的信息保存。二、 系統(tǒng)功能分析與設(shè)計設(shè)計的學(xué)生個人信息管理系統(tǒng),此系統(tǒng)能夠?qū)崿F(xiàn)學(xué)生信息錄入,查找修改的功能,要有信息錄入保存就必須有儲存數(shù)據(jù)的地方,在這里我選擇用文件來設(shè)計學(xué)生信息儲存,學(xué)生信息查找功能需要按學(xué)號查找,學(xué)生信息修改要先查找到需要修改的學(xué)生信息然后修改。系統(tǒng)體系設(shè)計如下學(xué)生個人信息系統(tǒng)學(xué)生信息錄入系統(tǒng)學(xué)生信息查詢系統(tǒng)學(xué)生信息修改系統(tǒng)學(xué)生信息錄入按學(xué)號查詢修改學(xué)生信息三、 數(shù)

3、據(jù)分析與設(shè)計在我的學(xué)生信息管理系統(tǒng)中,用文件來保存學(xué)生信息,定義文件并把文件放在和程序同一個文件夾下放進(jìn)去數(shù)個原始數(shù)據(jù),然后在程序中進(jìn)行錄入、查詢和修改。定義代碼如下:File file=new File(studentData.txt);file.createNewFile();文件如下:四、 設(shè)計思路(相關(guān)類介紹,以及類之間的關(guān)系圖)1. 相關(guān)類介紹JFrameDemo類是本系統(tǒng)的主類,是程序的主要功能實現(xiàn)類,它繼承自JFrame類。 b6.addActionListener(new ActionListener() )類是JFrameDemo的內(nèi)部類,實現(xiàn)按鈕b6的監(jiān)聽功能。 b7.ad

4、dActionListener(new ActionListener()是和相同的內(nèi)部類實現(xiàn)監(jiān)聽功能。與此相同類還有b1.addActionListener(new ActionListener()、b2.addActionListener(new ActionListener()等。2. 類之間關(guān)系java.awt.event.*類b7的內(nèi)部b6的內(nèi)部b5的內(nèi)部b4的內(nèi)部b3的內(nèi)部b2的內(nèi)部b1的內(nèi)部類JFrameDemo類JFrame類之間的關(guān)系圖五、 運行效果圖主界面如圖,可以點擊錄入、查詢和修改按鈕來選擇不同的JPanel界面。填寫學(xué)生信息,然后可以點擊提交按鈕提交信息或重置按鈕重置信

5、息。點擊查詢來到查詢界面,可以按學(xué)號查詢或顯示全部信息。 點擊修改按鈕來到修改界面,先輸入學(xué)號查詢,然后更改信息再點擊保存按鈕,為了驗證這一功能我們把小王改為小趙,然后在查詢界面中查學(xué)10007,運行如下:六、 代碼如下:import java.awt.Color;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFo

6、undException;import java.io.FileOutputStream;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import javax.swing.*; public class JFrameDemo extends JFrame String s123;char ch= ; int number1,number=5; JButton b1,b2,b3,b4,b5,b6,jb1,jb2,b7;JLabel l1,l2,l3,l4,l5,l6,l7,jl1,j

7、l2,jl3,jl4,jl5,jl6,jl7,jl8,jl9,jll1,jll2,jll3;JRadioButton r1,r2; JTextField t1,t2,t3,t4,t5,t6,jt1,jt2,jt3,jt4,jt5,jt6,jt7,jtt,jtt1;JPanel j1,j2,j3,j4; JTextArea jArea; public JFrameDemo() throws IOException File file=new File(studentData.txt);file.createNewFile(); FileInputStream fis=new FileInputS

8、tream(studentData.txt); File file1=new File(number.txt);file.createNewFile(); this.setTitle(學(xué)生個人信息管理系統(tǒng)); this.setLayout(null); r1=new JRadioButton(男); r2=new JRadioButton(女); t1=new JTextField(30); t2=new JTextField(30); /t3=new JTextField(30); t4=new JTextField(30); t5=new JTextField(30); t6=new JT

9、extField(30); j1=new JPanel(); j2=new JPanel(); j2.setLayout(null); j3=new JPanel(); j3.setLayout(null); j4=new JPanel(); j4.setLayout(null); b1=new JButton(錄入); b2=new JButton(修改); b3=new JButton(查詢); b4=new JButton(重置); b5=new JButton(提交); b6=new JButton(查詢); b7=new JButton(顯示全部信息); jll1=new JLabe

10、l(查找學(xué)生信息); jll1.setFont(new Font(Serif,Font.PLAIN,30);jll1.setBounds(200,20,300,30);jll2=new JLabel(輸入學(xué)號);jll2.setFont(new Font(Serif,Font.PLAIN,20);jll2.setBounds(90, 100, 80,30);jtt=new JTextField(30);jtt.setBounds( 190, 100, 80, 25);jArea=new JTextArea( 10, 570);jArea.setBounds( 10, 170, 580, 230

11、);b6.setBounds( 305, 100, 80, 25);b7.setBounds(405, 100, 120, 25); /JScrollPane scrollpane = new JScrollPane(jtt1);/ j4.add(scrollpane); /scrollpane.setBounds(100, 200, 20, 40); /add(j4 ); b6.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) FileReader fr = null;try f

12、r = new FileReader(number.txt); catch (FileNotFoundException e1) e1.printStackTrace();try number1=(int)fr.read(); catch (IOException e1) / TODO Auto-generated catch blocke1.printStackTrace();try fr.close(); catch (IOException e1) / TODO Auto-generated catch blocke1.printStackTrace(); if (number1!=-1

13、) number=number1; System.out.println(number); if(!jtt.getText().trim().equals() filefind(); elseJOptionPane.showMessageDialog(null,請輸入需要查詢學(xué)生的學(xué)號,溫馨提示,JOptionPane.INFORMATION_MESSAGE); public void filefind() byte a=new byte1000;int i;int findpersion=-1; String str=null;tryFileInputStream fis=new FileI

14、nputStream(studentData.txt);i=fis.read(a,0,1000); trystr=new String(a,0,i);catch(Exception ee)System.out.println(編碼沒有被發(fā)現(xiàn)+ee);fis.close();catch(FileNotFoundException e)System.out.println(file not found);catch(IOException e)e.printStackTrace();System.out.println(srgsgsrgge);System.out.println(str);Sys

15、tem.out.println(srgsgsrgge);String findstring=new Stringnumber;String sstr=new String5;findstring=str.split(n);String sfind=null; for(int j=0;jnumber+1;j+)if(findstringj.indexOf(jtt.getText()!=-1)findpersion=j;jArea.setText( findstringfindpersion);break; if(findpersion=-1)JOptionPane.showMessageDial

16、og(null, 查無此學(xué)生, 提示,JOptionPane.INFORMATION_MESSAGE); ); b7.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) byte a=new byte1000;int i;int findpersion=-1; String str=null;tryFileInputStream fis=new FileInputStream(studentData.txt);i=fis.read(a,0,1000); trystr=new Stri

17、ng(a,0,i);catch(Exception ee)System.out.println(編碼沒有被發(fā)現(xiàn)+ee);fis.close();catch(FileNotFoundException e1)System.out.println(file not found);catch(IOException e1)e1.printStackTrace();jArea.setText(str);); j4.add(jll1);j4.add(jll2);j4.add(jtt);j4.add(jArea); j4.add(b6);j4.add(b7); b4.addActionListener(n

18、ew ActionListener() public void actionPerformed(ActionEvent e) t1.setText(null);t2.setText(null);t4.setText(null);t5.setText(null);t6.setText(null); r1.setSelected(false); r2.setSelected(false); ); b5.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) String s=new Stri

19、ng();if(r1. isSelected() ) s=t1.getText()+ +t2.getText()+ +r1.getText()+ +t6.getText()+ +t5.getText()+ +t4.getText(); else s=t1.getText()+ +t2.getText()+ + r2.getText()+ +t6.getText()+ +t5.getText()+ +t4.getText();s=s+rn;byte a=s.getBytes(); tryFileOutputStream fos=new FileOutputStream(studentData.t

20、xt,true);fos.write(a); JOptionPane.showMessageDialog(null, 信息寫入成功, 提示,JOptionPane.INFORMATION_MESSAGE);fos.close(); number+;char char1=(char)number;FileWriter fw=new FileWriter(number.txt); fw.write(char1); fw.close();catch(IOException e1)e1.printStackTrace();); l1=new JLabel(學(xué)生信息錄入); l1.setFont(new

21、 Font(Serif,Font.PLAIN,30); l2=new JLabel(學(xué)號); l2.setFont(new Font(Serif,Font.PLAIN,20); l3=new JLabel(姓名); l3.setFont(new Font(Serif,Font.PLAIN,20); l4=new JLabel(專業(yè)); l4.setFont(new Font(Serif,Font.PLAIN,20); l5=new JLabel(身份證號); l5.setFont(new Font(Serif,Font.PLAIN,20); l6=new JLabel(班級); l6.setF

22、ont(new Font(Serif,Font.PLAIN,20); l7=new JLabel(性別); l7.setFont(new Font(Serif,Font.PLAIN,20); j1.add(b1); j1.add(b3); j1.add(b2); l1.setBounds(200,20,300,30); b4.setBounds(170,340,65,30); b5.setBounds(360,340,65,30); l2.setBounds(80, 130, 80, 30); t1.setBounds(160, 130, 80, 25); l3.setBounds( 300,

23、 130, 80, 25); t2.setBounds(380, 130, 80, 25); l7.setBounds(80, 180, 80, 30); /t3.setBounds(160, 180, 80, 25); l5.setBounds( 300, 180, 80, 25); t4.setBounds(380, 180, 130, 25); l4.setBounds(80, 230, 80, 25); t6.setBounds(160, 230, 125, 25); l6.setBounds(300, 230, 80, 25); t5.setBounds(380, 230, 80,

24、25); r1.setBounds(160,180,40,25 ); r2.setBounds(200,180,40,25 ); j2.add(l1); j2.add(b4); j2.add(b5); j2.add(l2); j2.add(t1); j2.add(l3); j2.add(t2); j2.add(l7); /j2.add(t3); j2.add(r1); j2.add(r2); j2.add(l5); j2.add(t4); j2.add(l4); j2.add(t6); j2.add(l6); j2.add(t5); jb1=new JButton(查詢); jb2=new J

25、Button(保存); jb1.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) FileReader fr = null;try fr = new FileReader(number.txt); catch (FileNotFoundException e1) e1.printStackTrace();try number1=(int)fr.read(); catch (IOException e1) / TODO Auto-generated catch blocke1.pri

26、ntStackTrace();try fr.close(); catch (IOException e1) / TODO Auto-generated catch blocke1.printStackTrace(); if (number1!=-1) number=number1; System.out.println(number); if(!jt1.getText().trim().equals() filefind(); elseJOptionPane.showMessageDialog(null,請輸入需要查詢學(xué)生的學(xué)號,溫馨提示,JOptionPane.INFORMATION_MES

27、SAGE); public void filefind() byte a=new byte1000;int i;int findpersion=-1; String str=null;tryFileInputStream fis=new FileInputStream(studentData.txt);i=fis.read(a,0,1000); trystr=new String(a,0,i);catch(Exception ee)System.out.println(編碼沒有被發(fā)現(xiàn)+ee);fis.close();catch(FileNotFoundException e)System.ou

28、t.println(file not found);catch(IOException e)e.printStackTrace();System.out.println(srgsgsrgge);System.out.println(str);System.out.println(srgsgsrgge);String findstring=new Stringnumber;String sstr=new String5;findstring=str.split(n);String sfind=null; for(int j=0;jnumber+1;j+)if(findstringj.indexO

29、f(jt1.getText()!=-1)findpersion=j;break; System.out.println(number);/number=5if(findpersion!=-1)sfind=findstring findpersion.toString(); sstr=sfind.split( ); jt2.setText(sstr0); jt3.setText(sstr1); jt4.setText(sstr2); jt5.setText(sstr3); jt6.setText(sstr4); jt7.setText(sstr5); elseJOptionPane.showMe

30、ssageDialog(null, 查無此學(xué)生, 提示,JOptionPane.INFORMATION_MESSAGE); ); jb2.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) if(!jt1.getText().trim().equals() System.out.println(cuysgdu+number); filefindd(); elseJOptionPane.showMessageDialog(null,請輸入需要查詢學(xué)生的學(xué)號,溫馨提示,JOptionPa

31、ne.INFORMATION_MESSAGE); public void filefindd() byte a1=new byte1000;int i;int findpersion=-1;String s2 =new String();s2=jt2.getText()+ +jt3.getText()+ +jt4.getText()+ +jt5.getText()+ +jt6.getText()+ +jt7.getText()+ ; String str = null;tryFileInputStream fis=new FileInputStream(studentData.txt);i=f

32、is.read(a1,0,1000);trystr=new String(a1,0,i);catch(Exception ee)System.out.println(編碼沒有被發(fā)現(xiàn)+ee);fis.close();catch(FileNotFoundException e)System.out.println(file not found);catch(IOException e)e.printStackTrace(); System.out.println(s2); String findstring=new Stringnumber; String string ;findstring=s

33、tr.split(n); int no = 0; for(int j=0;jnumber+1;j+) if(findstringj.indexOf(jt1.getText()!=-1) findstringj= s2; no=j; string =findstring0;for(int j=1;jnumber+1;j+)string =string+rn+ findstringj;System.out.println(thisd+string); System.out.println(number); string=string+rn; a1=string.getBytes(); tryFil

34、eOutputStream fos=new FileOutputStream(studentData.txt);fos.write(a1); JOptionPane.showMessageDialog(null, 信息修改成功, 提示,JOptionPane.INFORMATION_MESSAGE);fos.close();catch(IOException e1)e1.printStackTrace(); ); jt1=new JTextField(30); jt2=new JTextField(30); jt3=new JTextField(30); jt4=new JTextField(

35、30); jt5=new JTextField(30); jt6=new JTextField(30); jt7=new JTextField(30); jl1=new JLabel(輸入要改的學(xué)生學(xué)號); jl2=new JLabel(修改學(xué)生信息); jl2.setFont(new Font(Serif,Font.PLAIN,30); jl3=new JLabel(查詢結(jié)果&請修改); jl4=new JLabel(學(xué)號); jl5=new JLabel(姓名); jl6=new JLabel(性別); jl7=new JLabel(專業(yè)); jl8=new JLabel(班級); jl9

36、=new JLabel(身份證號); jl2.setBounds( 200,20,300,30 ); jt1.setBounds( 250,80,80,25 ); jt2.setBounds( 10, 160,80,25 ); jt3.setBounds( 100,160,80,25 ); jt4.setBounds( 195,160,40,25 ); jt5.setBounds( 245,160,125,25 ); jt6.setBounds( 380,160,80,25 ); jt7.setBounds( 470,160,130,25 ); jb1.setBounds( 380,80,80

37、,25 ); jb2.setBounds( 250, 300,80,60 ); jl1.setBounds( 100,80,160,25 ); jl3.setBounds( 240,120,200,25 );jl4.setBounds( 40,200,80,25 ); jl5.setBounds( 120,200,80,25 ); jl6.setBounds( 200,200,80,25 ); jl7.setBounds( 280,200,80,25 ); jl8.setBounds( 400,200,80,25 ); jl9.setBounds( 495,200,80,25 ); j3.add(jb1); j3.add(jb2); j3.add(jt1); j3.a

溫馨提示

  • 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論