




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
/一.引言項目的名稱商品房銷售中的客戶信息管理系統項目背景和目標商品房銷售中的客戶信息管理系統主要對客戶的個人基本信息進行管理,對商家提供查詢信息、增添信息、刪除信息等操作功能;對客戶提供信息查詢功能。我們的目標就是為該系統提供后臺連接數據庫程序設計以及前臺用戶界面設項目的可行性研究設計此系統需要java面向對象編程基礎,數據庫應用知識以及功能分析。根據目前所開設的課程,學生已經具備這樣的知識,有能力綜合java編程知識和數據庫應用知識做出一個這樣的客戶信息管理系統需求分析2.1系統概述此系統提供給客戶和商家。商家登陸后可以對基本信息表進行查看、增添新記錄和刪除記錄等操作??蛻舻顷懞竽懿樵兛蛻粜畔?。2.2系統運行環境 Java運行在eclipse軟件上,數據庫用mysql數據庫2.3功能需求描述商品房銷售中的客戶信息管理系統要面對商家和客戶。對于教師,需要查詢全部學生的基本信息和成績信息,并且可以對其進行修改。對于學生,不需要查詢自己的基本信息,只需要查詢成績。為了保護學生成績隱私,每位學生登錄系統后只能查詢自己的成績,而無法看到別人的成績三、系統設計3.1開發與設計的總體思想教師方面:教師通過自己的用戶名和密碼登錄后,進入教師主界面,在這個主界面里,可以選擇要操作的類別,即查詢功能還是修改功能。在查詢功能里面,可以選擇是查詢學生基本信息,還是查詢學生成績信息。在查詢學生基本信息時,可以從依據不同字段,即學生信息表的不同屬性進行查找。在查找學生成績信息時,只能依據學生姓名和學號進行查找。在修改功能里面,包括對學生基本信息表和學生成績表進行增加和刪除記錄學生方面:學生通過自己的用戶名和密碼登錄此系統后,可以查詢自己本學期的各科成績信息商品房銷售中的客戶信息管理系統3.2系統模塊結構圖商品房銷售中的客戶信息管理系統商家登陸客戶登陸商家登陸客戶登陸商家操作界面房型與房價信息商家操作界面房型與房價信息3.3數據庫結構設計為了支持此學生信息管理系統,創建數據庫studentmanage。在這個數據庫中包含四個表:student表,teacher表,studentlogin表和score表。截圖如下:在student〔學生基本信息表中,有五個屬性列,分別為:num〔學號,sname〔學生姓名姓名,sex〔性別,age〔年齡,dept〔系別。其基本數據類型分別為:int,char,char,int,char。當查詢學生基本信息時,從此表中獲取數據。截圖如下:在teacher〔教師登陸表中,有兩個屬性列,分別為:tname〔教師姓名,password〔登錄密碼。其基本數據類型分別為:char,char。當教師用戶登陸此系統時,從該表獲取數據。截圖如下:在studentlogin〔學生登錄表中,有兩個屬性列,分別為:sname〔學生姓名,password〔登錄密碼。其基本數據類型分別為:char,char。當學生用戶登陸此系統時,從該表獲取數據。截圖如下:在score〔學生成績表中,有五個屬性列,分別為:num〔學號,sname〔學生姓名,course〔課程名稱,score〔考試成績,credit〔學分。其基本數據類型分別為:int,char,char,int,int。當查詢學生成績信息時,從此表獲取數據。截圖如下:3.4模塊設計總主界面登陸后,可以選擇用戶,是學生用戶或者教師用戶。如果選擇學生用戶,則進入學生登錄界面,在這個界面上輸入學生姓名和用戶密碼。輸入后單擊"成績查詢"按鈕,若密碼正確,這顯示該學生本人本學期成績,若密碼不正確,這提示密碼錯誤。如果選擇教師用戶,則進入教師登陸界面,在這個界面上輸入教師姓名和用戶密碼,輸入后單擊"登錄"按鈕,則進入教師主界面。在教師主界面可以選擇進行查詢操作還是修改操作。在查詢操作中包含查詢學生基本信息和查詢學生成績信息。若要查詢學生基本信息,點擊菜單項則進入學生基本信息檢索界面,在此界面的檢索方式中選擇要檢索的數據屬性,在檢索內容框中輸入檢索的具體信息,例如,檢索"姓名"字段時,要鍵入某個學生姓名。輸入后,單擊"檢索"按鈕,則開始數據庫查詢。如果數據庫檢索到所需信息,這生成列表顯示檢索結構,如果沒有所需信息,則列表中的內容為空。若要查詢學生成績信息,則點擊學生成績查詢菜單項,進入成績查詢界面。在此界面的文本框中輸入要查詢成績的學生姓名,然后單擊檢索按鈕。若數據庫中有此學生的成績信息,則生成列表顯示成績信息,若沒有此記錄,則列表內容為空。如果教師要進行修改操作,則在教師主界面上選擇修改菜單項,在此項中,選擇要修改的具體內容,總共有四項修改操作:增加新生信息,刪除畢業生信息〔這兩個是對學生基本信息表的操作,增加成績信息,刪除成績信息〔這兩個是對學生成績信息表的操作。在增加信息操作中,按照標簽提示一次輸入要增添的記錄值,輸入完畢后,單擊"添加"按鈕,若輸入成功,則提示成功,若輸入失敗,則提示失敗。在刪除信息操作中,輸入要刪除信息的學生姓名,單擊"刪除"按鈕,若刪除成功,則提示成功,若刪除失敗則提示失敗。以上就是該學生信息管理系統的操作步驟。3.5系統流程描述四、系統實現本系統保存在studentmanage包里其中包含四個包:connection包,dao包,model包,ui包1.Connection包中的類:〔1DBconnection類:此類設置程序與數據庫的連接,通過設置驅動類型和數據源來確定要連接的數據庫。若連接成功,提示:connectionsuccess,若連接失敗,提示:connectionfailureDBconnection類源代碼:packageconnection;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;publicclassDBConnection{publicstaticConnectioncon=null;publicstaticConnectiongetConnection<>{ try{ StringdbDriver="com.mysql.jdbc.Driver"; Class.forName<dbDriver>; System.out.println<"DriverSuceess">; }catch<ClassNotFoundExceptione>{ System.out.println<"Drivernotfound">; e.printStackTrace<>; } try{ con=DriverManager.getConnection<"jdbc:mysql://:3306/studentmanage","root","root">; System.out.println<"ConnectionSuceess">; }catch<SQLExceptione>{ System.out.println<"Connetionfailure">; e.printStackTrace<>; } returncon;}publicstaticvoidcloseConnection<>{ if<con!=null> try{ con.close<>; System.out.println<"databaseclosesuccess">; }catch<SQLExceptione>{ System.out.println<"closefailure">; e.printStackTrace<>; }}}2.Dao包中的類:〔1StudentDao類:此類中有四個方法,studentLogin,addStudent,deleteStudent,queryStuden,作用分別是控制學生登陸,增加學生基本信息,查詢學生基本信息,刪除學生基本信息。studentLogin〔方法中,有兩個參數,分別傳給select語句中的sname〔學生姓名和password〔登錄密碼,利用select語句在studentlogin表中檢索學生登錄信息。若存在此信息,返回true,否則返回falseaddStudent<>方法中,有五個參數,分別傳給insert語句中的num〔學號,sname〔學生姓名,age〔年齡,sex〔性別和dept〔系別,利用insert語句向student學生基本信息表中插入學生記錄。若插入成功,返回true,否則返回falsedeleteStudent〔方法中,有一個參數,傳給delete語句中的sname〔學生姓名,利用delete語句,把student表中相關學生信息刪除。若刪除成功,返回true,否則返回falsequeryStuden〔方法中,有兩個參數,分別傳給select語句中的field<查找方式>和key〔查找內容,利用select語句,從student表中檢索學生基本信息。若存在此信息,則返回一個ArrayList類的對象lis〔表格,否則,異常處理StudentDao類源代碼:packagedao;importjava.sql.Connection;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjava.util.ArrayList;importmodel.Student;importconnection.DBConnection;publicclassStudentDao{ publicbooleanstudentLogin<Stringsname,Stringpassword>{ DBConnectiondb=newDBConnection<>; Connectioncon=db.getConnection<>; booleanisfound=false; PreparedStatementpst; try{ pst=con.prepareStatement<"select*fromstudentloginwheresname=?andpassword=?">;pst.setString<1,sname>; pst.setString<2,password>;ResultSetrs=pst.executeQuery<>; if<rs.next<>> isfound=true; }catch<SQLExceptione>{ e.printStackTrace<>; } System.out.println<isfound>; returnisfound; } publicbooleanaddStudent<intnum,Stringsname,Stringsex,intage, Stringdept>{ Connectioncon=DBConnection.getConnection<>; PreparedStatementpst; try{ pst=con.prepareStatement<"insertintostudentvalues<?,?,?,?,?>">;pst.setInt<1,num>; pst.setString<2,sname>; pst.setString<3,sex>; pst.setInt<4,age>; pst.setString<5,dept>; intcount=pst.executeUpdate<>;//返回修改的記錄數 if<count==1> returntrue; else returnfalse; }catch<SQLExceptione>{ e.printStackTrace<>;} returnfalse; } publicArrayListqueryStudent<Stringfield,Stringkey>{ ArrayListlis=newArrayList<>; Connectioncon=DBConnection.getConnection<>; Statementstm; try{ stm=con.createStatement<>; Stringsql="select*fromstudentwhere"+field+"like'%" +key+"%'"; System.out.println<sql>; ResultSetrs=stm.executeQuery<sql>; while<rs.next<>>{ Studentstudent=newStudent<rs.getInt<1>,rs.getString<2>,rs.getString<3>,rs.getInt<4>,rs.getString<5>>;lis.add<student>; } }catch<SQLExceptione>{ e.printStackTrace<>; } returnlis; } publicbooleandeleteStudent<Stringkey>{ Connectioncon=DBConnection.getConnection<>; Statementstm; try{ stm=con.createStatement<>; Stringsql="deletefromstudentwheresnamelike'%" +key+"%'"; System.out.println<sql>; intcount=stm.executeUpdate<sql>; if<count==1> returntrue; else returnfalse; }catch<SQLExceptione>{ e.printStackTrace<>; } returnfalse; }}〔2TeacherDao類:此類中有一個方法:queryTeacher,作用是控制教師登陸queryTeacher〔方法中,有兩個參數,分別傳給select語句中的tname〔教師姓名和password〔登陸密碼,利用select語句在teacher表中檢索教師登陸信息。若存在此信息,返回true,否則返回falseTeacherDao類源代碼:packagedao;ion;t;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importconnection.DBConnection;publicclassTeacherDao{ publicbooleanqueryTeacher<Stringtname,Stringpassword>{ DBConnectiondb=newDBConnection<>; Connectioncon=db.getConnection<>; booleanisfound=false; PreparedStatementpst; try{ pst=con.prepareStatement<"select*fromteacherwheretname=?andpassword=?">;pst.setString<1,tname>; pst.setString<2,password>;ResultSetrs=pst.executeQuery<>; if<rs.next<>> isfound=true; }catch<SQLExceptione>{ e.printStackTrace<>; } System.out.println<isfound>; returnisfound; } publicstaticvoidmain<String[]args>{ }}〔3ScoreDao類:此類中有四個方法,queryScore,queryScore1,addScore,deleteScor作用分別是為教師用戶提供查詢學生成績信息功能,為學生用戶提供詢本人成績信息功能,添加成績信息,刪除成績信息。queryScore〔方法中,有一個參數,傳給select語句中的sname〔學生姓名,利用select語句,查詢學生成績信息表中的內容。若查詢成功,則返回一個ArrayList類的對象lis〔表格,否則,異常處理queryScore1〔方法中,有一個參數,傳給傳給select語句中的sname〔學生姓名,這個sname的學生用戶登錄時輸入的姓名。即此類的作用是每個學生登陸只能查看本人成績。若查詢成功,則返回一個ArrayList類的對象lis〔表格,否則,異常處理addScore〔方法中,有五個參數,分別傳給insert語句中的num<學號>,sname〔學生姓名,course〔課程名稱,score〔成績,credit〔學分。利用insert語句,將這些記錄寫入score表中。若插入成功返回true,否則返回falsedeleteScore〔方法中,有一個參數,傳給delete語句中的sname〔學生姓名,利用delete語句,把score表中相關學生信息刪除。若刪除成功,返回true,否則返回falseScoreDao類源代碼:packagedao;importjava.sql.Connection;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjava.util.ArrayList;importui.StudentLoginUI;importmodel.Score;importmodel.Student;importconnection.DBConnection;publicclassScoreDao{ publicArrayListqueryScore<Stringkey>{ ArrayListlis=newArrayList<>; Connectioncon=DBConnection.getConnection<>; Statementstm; try{ stm=con.createStatement<>; Stringsql="select*fromscorewheresnamelike'%"+key+"%'"; System.out.println<sql>;ResultSetrs=stm.executeQuery<sql>; while<rs.next<>>{ Scorescore=newScore<rs.getInt<1>,rs.getString<2>,rs.getString<3>,rs.getInt<4>,rs.getInt<5>>;lis.add<score>; } }catch<SQLExceptione>{ e.printStackTrace<>; } returnlis; } publicArrayListqueryScore1<Stringkey>{ ArrayListlis=newArrayList<>; Connectioncon=DBConnection.getConnection<>; Statementstm; try{ stm=con.createStatement<>; Stringsql="select*fromscorewheresnamelike'%"+StudentLoginUI.st1+"%'"; System.out.println<sql>;ResultSetrs=stm.executeQuery<sql>; while<rs.next<>>{ Scorescore=newScore<rs.getInt<1>,rs.getString<2>,rs.getString<3>,rs.getInt<4>,rs.getInt<5>>;lis.add<score>; } }catch<SQLExceptione>{ e.printStackTrace<>; } returnlis; } publicbooleanaddScore<intnum,Stringsname,Stringcourse,intscore, intcredit>{ Connectioncon=DBConnection.getConnection<>; PreparedStatementpst; try{ pst=con.prepareStatement<"insertintoscorevalues<?,?,?,?,?>">;pst.setInt<1,num>; pst.setString<2,sname>;pst.setString<3,course>; pst.setInt<4,score>; pst.setInt<5,credit>; intcount=pst.executeUpdate<>;//返回修改的記錄數 if<count==1> returntrue; else returnfalse; }catch<SQLExceptione>{ e.printStackTrace<>; } returnfalse; } publicbooleandeleteScore<Stringkey>{ Connectioncon=DBConnection.getConnection<>; Statementstm; try{ stm=con.createStatement<>; Stringsql="deletefromscorewheresnamelike'%"+key+"%'"; System.out.println<sql>; intcount=stm.executeUpdate<sql>; if<count==1> returntrue; else returnfalse; }catch<SQLExceptione>{ e.printStackTrace<>; } returnfalse; }}3.model包中的類:〔1Score類:此類中有五個成員變量,intnum;Stringsname;Stringcourse;intscore;intcredit;十個成員方法,分別獲取和設置這五個變量,即為score表中五個屬性的記錄值,均為getXXX<>setXXX<>方法,還有一個構造方法,用于調用其對象時對成員變量賦值Score類源代碼:packagemodel;publicclassScore{ intnum; Stringsname; Stringcourse; intscore; intcredit; publicintgetNum<>{ returnnum; } publicvoidsetNum<intnum>{ this.num=num; } publicStringgetSname<>{ returnsname; } publicvoidsetSname<Stringsname>{ this.sname=sname; } publicStringgetCourse<>{ returncourse; } publicvoidsetCourse<Stringcourse>{ this.course=course; } publicintgetScore<>{ returnscore; } publicvoidsetScore<intscore>{ this.score=score; } publicintgetCredit<>{ returncredit; } publicvoidsetCredit<intcredit>{ this.credit=credit; } publicScore<intnum,Stringsname,Stringcourse,intscore,intcredit> {super<>;this.num=num;this.sname=sname;this.course=course;this.score=score;this.credit=credit;}}〔2Student類:此類中有五個成員變量,intnum;Stringsname;Stringsex;intage;Stringdept;十個成員方法,分別獲取和設置這五個變量,即為student表中五個屬性的記錄值,均為getXXX<>setXXX<>方法,還有一個構造方法,用于調用其對象時對成員變量賦值Student類源代碼:packagemodel;publicclassStudent{ intnum; Stringsname; Stringsex; intage; Stringdept; publicintgetNum<>{ returnnum; } publicvoidsetNum<intnum>{ this.num=num; } publicStringgetSname<>{ returnsname; } publicvoidsetSname<Stringsname>{ this.sname=sname; } publicStringgetSex<>{ returnsex; } publicvoidsetSex<Stringsex>{ this.sex=sex; } publicintgetAge<>{ returnage; } publicvoidsetAge<intage>{ this.age=age; } publicStringgetDept<>{ returndept; } publicvoidsetDept<Stringdept>{ this.dept=dept; } publicStudent<intnum,Stringsname,Stringsex,intage,Stringdept> { super<>; this.num=num; this.sname=sname; this.sex=sex; this.age=age; this.dept=dept; }}4.ui包中的類:〔1LoginUI類:此類為登陸界面,在這個界面上,設置有兩個按鈕,學生按鈕,教師按鈕。給這兩個按鈕注冊事件addActionListener,分別在內部類TeacherLoginActionListene和StudentLoginActionListener中的默認方法actionPerformed〔中創建TeacherLoginUI類和StudentLoginUI類的對象,即打開教師登陸界面和學生登錄界面,并將原登陸界面關閉。LoginUI類源代碼:packageui;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassLoginUIextendsJFrame{ JLabell1; JButtonbt1,bt2; Containercp; publicLoginUI<>{ l1=newJLabel<"請選擇用戶類型">; bt1=newJButton<"教師">; bt2=newJButton<"學生">; JPanelp1=newJPanel<>;p1.setLayout<null>; l1.setBounds<150,150,120,40>; p1.add<l1>; bt1.setBounds<120,230,80,30>; p1.add<bt1>; bt2.setBounds<220,230,80,30>; p1.add<bt2>; bt1.addActionListener<newTeacherLoginActionListener<>>;//注冊事件 bt2.addActionListener<newStudentLoginActionListener<>>;//注冊事件 cp=getContentPane<>; this.setBounds<200,200,p1.getHeight<>,p1.getHeight<>>; cp.add<p1>; this.setTitle<"用戶登錄界面">; this.setSize<400,400>; this.setVisible<true>; this.addWindowListener<newWindowAdapter<>{ publicvoidwindowClosing<WindowEvente>{ System.exit<0>; } }>; } classTeacherLoginActionListenerimplementsActionListener{ publicvoidactionPerformed<ActionEvente>{ newTeacherLoginUI<>; dispose<>; } }classStudentLoginActionListenerimplementsActionListener{ publicvoidactionPerformed<ActionEvente>{ newStudentLoginUI<>; dispose<>; } } publicstaticvoidmain<String[]args>{ newLoginUI<>; }}執行截圖如下:〔2StudentLoginUI類:此類為學生登陸界面,在這個界面上有兩個文本框,分別輸入學生姓名和登錄密碼,還有兩個按鈕,登陸和退出。輸入后,從兩個文本框中獲取用戶輸入的內容,點擊"登陸"按鈕時,調用StudentDao類中的studentLogin〔方法驗證是否存在該用戶。若存在,則創建StudentScoreUI類的對象,即打開學生成績界面,顯示此登陸學生的成績信息,若不存在,則提示密碼錯誤。StudentLoginUI類源代碼:packageui;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importdao.StudentDao;publicclassStudentLoginUIextendsJFrame{ JLabell1,l2; JTextFieldt1; JPasswordFieldt2; JButtonbt1,bt2; Containercp; publicstaticStringst1; publicStringst2; publicStudentLoginUI<>{ l1=newJLabel<"學生姓名">; l2=newJLabel<"密碼">; t1=newJTextField<12>; t2=newJPasswordField<12>; bt1=newJButton<"成績查詢">; bt2=newJButton<"退出">; JPanelp1=newJPanel<>; p1.setLayout<null>; l1.setBounds<150,150,80,40>; p1.add<l1>; t1.setBounds<250,150,80,30>; p1.add<t1>; l2.setBounds<150,190,80,40>; p1.add<l2>; t2.setBounds<250,190,80,30>; p1.add<t2>; bt1.setBounds<150,230,120,30>; p1.add<bt1>; bt2.setBounds<280,230,80,30>; p1.add<bt2>; bt1.addActionListener<newLoginActionListener<>>;//注冊事件 bt2.addActionListener<newExitActionListener<>>;//注冊事件 cp=getContentPane<>; this.setBounds<200,200,p1.getHeight<>,p1.getHeight<>>; cp.add<p1>; this.setTitle<"學生登錄界面">; this.setSize<400,400>; this.setVisible<true>; this.addWindowListener<newWindowAdapter<>{ publicvoidwindowClosing<WindowEvente> { System.exit<0>; } }>; } classLoginActionListenerimplementsActionListener{ publicvoidactionPerformed<ActionEvente>{ st1=t1.getText<>; st2=t2.getText<>; StudentDaooneStudentDao=newStudentDao<>; booleanisSuccess=oneStudentDao.studentLogin<st1,st2>; if<isSuccess>{ newStudentScoreUI<>; dispose<>; }else JOptionPane.showMessageDialog<null,"用戶名密碼錯誤","提示信息", JOptionPane.INFORMATION_MESSAGE>; } } classExitActionListenerimplementsActionListener{ publicvoidactionPerformed<ActionEvente>{ System.exit<0>; } } publicstaticvoidmain<String[]args>{ newStudentLoginUI<>; }}執行截圖如下:〔3StudentScoreUI類:此類為學生成績界面,此類中有一個標簽和一個表格。標簽中從StudentLoginUI類中獲取學生登錄時使用的用戶名,顯示在標簽中以表示以下是某某同學的成績信息。表格中為此學生的成績。調用ScoreDao類中的queryScore1〔,將得到的ArrayList對象lis放入Vector對象中,形成表格。StudentScoreUI類源代碼:packageui;importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;importjava.util.*;importjavax.swing.event.*;importjavax.swing.table.DefaultTableModel;importmodel.Score;importdao.ScoreDao;publicclassStudentScoreUIextendsJFrame{ Stringaa=StudentLoginUI.st1;JLabelselectionLabel; JPaneltopPanel; Containercontainer; JTabletable; JScrollPanebookScrollPane; JPanelbottomPanel; publicStudentScoreUI<>{ container=this.getContentPane<>; selectionLabel=newJLabel<aa+"同學本學期成績如下">; topPanel=newJPanel<>; topPanel.setLayout<newFlowLayout<FlowLayout.CENTER>>; topPanel.add<selectionLabel>; this.add<BorderLayout.NORTH,topPanel>; table=newJTable<>; bookScrollPane=newJScrollPane<table>; this.add<BorderLayout.CENTER,bookScrollPane>; bottomPanel=newJPanel<>; this.add<BorderLayout.SOUTH,bottomPanel>; this.setTitle<"學生成績查詢">; this.setSize<600,450>; this.setVisible<true>; ScoreDaooneScore=newScoreDao<>; ArrayListlis=oneScore.queryScore<aa>; Vector<String>head=newVector<>; head.add<"學號">; head.add<"姓名">; head.add<"學科">; head.add<"成績">; head.add<"學分">; Vector<Vector>content=newVector<>; for<inti=0;i<lis.size<>;i++>{ Vectorrow=newVector<>; ScoreoneScore1=<Score>lis.get<i>; row.add<oneScore1.getNum<>>; row.add<oneScore1.getSname<>>; row.add<oneScore1.getCourse<>>; row.add<oneScore1.getScore<>>; row.add<oneScore1.getCredit<>>; content.add<row>; } DefaultTableModelmodel=newDefaultTableModel<content,head>; table.setModel<model>; repaint<>; }}執行截圖如下:〔4TeacherLoginUI類:此類為教師登陸界面,在這個界面上有兩個文本框,分別輸入教師姓名和登錄密碼,還有兩個按鈕,登陸和退出。輸入后,從兩個文本框中獲取用戶輸入的內容,點擊"登陸"按鈕時,調用TeacherDao類中的queryTeacher〔方法驗證是否存在該用戶。若存在創建TeacherMainUI類的對象,即打開教師主界面,若不存在,則提示密碼錯誤。TeacherLoginUI類源代碼:packageui;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importdao.TeacherDao;publicclassTeacherLoginUIextendsJFrame{ JLabell1,l2; JTextFieldt1; JPasswordFieldt2; JButtonbt1,bt2; Containercp; publicTeacherLoginUI<>{ l1=newJLabel<"教師姓名">; l2=newJLabel<"密碼">; t1=newJTextField<12>; t2=newJPasswordField<12>; bt1=newJButton<"登錄">; bt2=newJButton<"退出">; JPanelp1=newJPanel<>; p1.setLayout<null>; l1.setBounds<150,150,80,40>; p1.add<l1>; t1.setBounds<250,150,80,30>; p1.add<t1>; l2.setBounds<150,190,80,40>; p1.add<l2>; t2.setBounds<250,190,80,30>; p1.add<t2>; bt1.setBounds<150,230,80,30>; p1.add<bt1>; bt2.setBounds<250,230,80,30>; p1.add<bt2>; bt1.addActionListener<newLoginActionListener<>>;//注冊事件 bt2.addActionListener<newExitActionListener<>>;//注冊事件 cp=getContentPane<>; this.setBounds<200,200,p1.getHeight<>,p1.getHeight<>>; cp.add<p1>; this.setTitle<"教師登錄界面">; this.setSize<400,400>; this.setVisible<true>; this.addWindowListener<newWindowAdapter<>{ publicvoidwindowClosing<WindowEvente> { System.exit<0>; } }>; } classLoginActionListenerimplementsActionListener{ publicvoidactionPerformed<ActionEvente>{ Stringst1=t1.getText<>; Stringst2=t2.getText<>; TeacherDaooneTeacherDao=newTeacherDao<>; booleanisSuccess=oneTeacherDao.queryTeacher<st1,st2>; if<isSuccess>{ newTeacherMainUI<>; dispose<>; }else JOptionPane.showMessageDialog<null,"用戶名密碼錯誤","提示信息", JOptionPane.INFORMATION_MESSAGE>; } } classExitActionListenerimplementsActionListener{ publicvoidactionPerformed<ActionEvente>{ System.exit<0>; } } publicstaticvoidmain<String[]args>{ newTeacherLoginUI<>; }}執行截圖如下:〔5TeacherMainUI類:此類為教師主界面類,在此界面上有一個菜單欄,三個菜單:文件,查詢,修改。其中"文件"菜單中有"退出"菜單項,點擊時跳出對話框問是否真的退出,若點擊是,窗口關閉,若點擊否,回復原界面。"查詢"菜單中有"學生基本信息"和"學生成績信息"兩個菜單項:當點擊"學生基本信息"時,通過注冊事件,創建InformationQueryUI類的對象,即打開查詢學生基本信息的窗口,當點擊"學生成績信息"時,通過注冊事件,創建ScoreQueryUI類的對象,即打開查詢學生成績信息的窗口。修改菜單中有"增加新生信息""刪除畢業生信息""增加成績信息"和"刪除成績信息"四個菜單項,當點擊"增加新生信息"時,通過注冊事件,創建StudentAddUI類的對象,即打開添加學生基本信息的窗口,當點擊"刪除畢業生信息"時,通過注冊事件,創建StudentDeleteUI類的對象,即打開刪除學生基本信息的窗口,當點擊"增加成績信息"時,通過注冊事件,創建ScoreAddUI類的對象,即打開添加成績信息的窗口,當點擊"刪除成績信息"時,通過注冊事件,創建ScoreDeleteUI類的對象,即打開刪除成績信息的窗口。TeacherMainUI類源代碼:packageui;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassTeacherMainUIextendsJFrame{Containerctp;TeacherMainUI<>{ ctp=this.getContentPane<>; this.setTitle<"歡迎進入學生管理系統!">; ctp.setLayout<newBorderLayout<>>; JMenuBarmenuBar=newJMenuBar<>; buildMainMenu<menuBar>; this.setJMenuBar<menuBar>; this.setBounds<100,100,400,300>; this.setVisible<true>; } publicvoidbuildMainMenu<JMenuBarmenuBar>{JMenufileMenu=newJMenu<"文件">;JMenuItemexitMenuItem=newJMenuItem<"退出">; exitMenuItem.addActionListener<newExitActionListener<>>;//注冊事件 fileMenu.add<exitMenuItem>; menuBar.add<fileMenu>; JMenuqueryMenu=newJMenu<"查詢">; JMenuItemqueryMenuItem=newJMenuItem<"學生基本信息">; JMenuItemqueryScoreMenuItem=newJMenuItem<"學生成績查詢">; queryMenuItem.addActionListener<newQueryActionListener<>>;//注冊事件 queryScoreMenuItem.addActionListener<newQueryScoreActionListener<>>;//注冊事件 queryMenu.add<queryMenuItem>; queryMenu.add<queryScoreMenuItem>; menuBar.add<queryMenu>; JMenuchangeMenu=newJMenu<"修改">; JMenuItemaddMenuItem=newJMenuItem<"增加新生信息">; JMenuItemdeleteMenuItem=newJMenuItem<"刪除畢業生信息">; JMenuItemaddScoreMenuItem=newJMenuItem<"增加成績信息">; JMenuItemdeleteScoreMenuItem=newJMenuItem<"刪除成績信息">; addMenuItem.addActionListener<newAddActionListener<>>;//注冊事件 deleteMenuItem.addActionListener<newDeleteActionListener<>>;//注冊事件 addScoreMenuItem.addActionListener<newAddScoreActionListener<>>;//注冊事件 deleteScoreMenuItem.addActionListener<newDeleteScoreActionListener<>>;//注冊事件 changeMenu.add<addMenuItem>; changeMenu.add<deleteMenuItem>; changeMenu.add<addScoreMenuItem>; changeMenu.add<deleteScoreMenuItem>; menuBar.add<changeMenu>; } classExitActionListenerimplementsActionListener{ publicvoidactionPerformed<ActionEvente>{ intresult=JOptionPane.showConfirmDialog<null,"真的要推出嗎?","提示信息", JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE, null>; if<result==0> System.exit<0>; elseif<result==1>{ } } } classQueryScoreActionListenerimplementsActionListener{ publicvoidactionPerformed<ActionEvente>{ newScoreQueryUI<>; } } classQueryActionListenerimplementsActionListener{ publicvoidactionPerformed<ActionEvente>{ newInformationQueryUI<>; } } classAddActionListenerimplementsActionListener{ publicvoidactionPerformed<ActionEvente>{ newStudentAddUI<>; } } classDeleteActionListenerimplementsActionListener{ publicvoidactionPerformed<ActionEvente>{ newStudentDeleteUI<>; } } classAddScoreActionListenerimplementsActionListener{ publicvoidactionPerformed<ActionEvente>{ newScoreAddUI<>; } } classDeleteScoreActionListenerimplementsActionListener{ publicvoidactionPerformed<ActionEvente>{ newScoreDeleteUI<>; } } publicstaticvoidmain<String[]args>{ newTeacherMainUI<>; }}執行截圖如下:〔6InformationQueryUI類:此類為學生基本信息查詢界面類,在此界面上有一個標簽,一個下拉列表框,一個文本框和一個按鈕。點擊下拉列表框時,可以選擇要檢索的方式,即要檢索的屬性,單擊時,通過注冊事件,在內部類的方法里獲取所點擊的屬性名稱,保存在一個String型的變量里。在文本框中輸入要檢索的屬性內容,單擊"檢索"按鈕時,通過注冊事件,在內部類的方法中把剛才獲取的屬性參數和內容參數傳給StudentDao類的queryStudent〔方法,從而獲取檢索內容,再把檢索得到的內容通過Vector對象放入ArrayList類的對象lis中,從而使檢索結果顯示在表格中。InformationQueryUI類源代碼:packageui;importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;importjava.util.*;importjavax.swing.event.*;importjavax.swing.table.*;importmodel.Student;importdao.StudentDao;publicclassInformationQueryUIextendsJFrame{ JLabelselectionLabel; JComboBoxfieldComboBox; JPaneltopPanel; JButtonretrievalButton; JTextFieldkeywordText; Containercontainer; StringfieldSelected; intselectedNum; JTabletable; JScrollPanebookScrollPane; JPanelbottomPanel; publicInformationQueryUI<>{ container=this.getContentPane<>; selectionLabel=newJLabel<"檢索方式">; fieldComboBox=newJComboBox<>; fieldComboBox.addItem<"請選擇...">; fieldComboBox.addItem<"學號">; fieldComboBox.addItem<"姓名">; fieldComboBox.addItem<"年齡">; fieldComboBox.addItem<"性別">; fieldComboBox.addItem<"系別">; fieldComboBox.addItemListener<newSelectedListener<>>;//下拉列表框注冊事件注冊事件 keywordText=newJTextField<"",20>; retrievalButton=newJButton<"檢索">; topPanel=newJPanel<>; topPanel.setLayout<newFlowLayout<FlowLayout.LEFT>>; keywordText.setSize<topPanel.getWidth<>/2,topPanel.getWidth<>>; topPanel.add<selectionLabel>; topPanel.add<fieldComboBox>; topPanel.add<keywordText>; topPanel.add<retrievalButton>; this.add<BorderLayout.NORTH,topPanel>; retrievalButton.addActionListener<newRetrievalActionListener<>>;//給檢索按鈕注冊事件 table=newJTable<>; bookScrollPane=newJScrollPane<table>; this.add<BorderLayout.CENTER,bookScrollPane>; bottomPanel=newJPanel<>; this.add<BorderLayout.SOUTH,bottomPanel>; this.setTitle<"學生信息檢索查詢系統">; this.setSize<600,450>; this.setVisible<true>; } classSelectedListenerimplementsItemListener{ publicvoiditemStateChanged<ItemEventevent>{ if<event.getStateChange<>==ItemEvent.SELECTED>{ selectedNum=fieldComboBox.getSelectedIndex<>;//獲取文本信息 } } } classRetrievalActionListenerimplementsActionListener{ publicvoidactionPerformed<ActionEventevent>{ switch<selectedNum>{ case1: fieldSelected="num"; break; case2: fieldSelected="sname"; break; case3: fieldSelected="age"; break; case4: fieldSelected="sex"; break; case5: fieldSelected="dept"; break; } Stringkey=keywordText.getText<>; StudentDaooneStudentDao=newStudentDao<>; ArrayListlis=oneStudentDao.queryStudent<fieldSelected,key>; Vector<String>head=newVector<>; head.add<"學號">; head.add<"姓名">; head.add<"年齡">; head.add<"性別">; head.add<"系別">; Vector<Vector>content=newVector<>; for<inti=0;i<lis.size<>;i++>{ Vectorrow=newVector<>; StudentoneStudent=<Student>lis.get<i>; row.add<oneStudent.getNum<>>; row.add<oneStudent.getSname<>>; row.add<oneStudent.getAge<>>; row.add<oneStudent.getSex<>>; row.add<oneStudent.getDept<>>; content.add<row>; } DefaultTableModelmodel=newDefaultTableModel<content,head>; table.setModel<model>; repaint<>; } } publicstaticvoidmain<String[]args>{ newInformationQueryUI<>; }}執行截圖如下:〔7ScoreQueryUI類:此類為學生成績查詢界面類,在此界面有一個標簽,一個文本框,一個按鈕。在文本框中輸入要查詢成績的學生姓名,單擊"查詢"按鈕時,通過注冊事件,在內部類的方法里,獲取從文本框中獲取的學生姓名信息,并把此信息作為實參傳給ScoreDao類的queryScore〔方法,得到查詢結構。再把查詢結構通過Vector對象放入ArrayList類的對象lis中,從而使檢索結果顯示在表格中。ScoreQueryUI類源代碼:packageui;importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;importjava.util.*;importjavax.swing.event.*;importjavax.swing.table.DefaultTableModel;importmodel.Score;importdao.ScoreDao;publicclassScoreQueryUIextendsJFrame{ JLabelselectionLabel; JPaneltopPanel; JButtonretrievalButton; JTextFieldkeywordText; Containercontainer; StringfieldSelected; intselectedNum; JTabletable; JScrollPanebookScrollPane; JPanelbottomPanel; publicScoreQueryUI<>{ container=this.getContentPane<>; selectionLabel=newJLabel<"學生姓名">; keywordText=newJTextField<"",20>; retrievalButton=newJButton<"查詢">; topPanel=newJPanel<>; topPanel.setLayout<newFlowLayout<FlowLayout.LEFT>>; keywordText.setSize<topPanel.getWidth<>/2,topPanel.getWidth<>>; topPanel.add<selectionLabel>; topPanel.add<keywordText>; topPanel.add<retrievalButton>; this.add<BorderLayout.NORTH,topPanel>; retrievalButton.add
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 花卉種養殖管理制度
- 茶企業公司管理制度
- 草莓園室內管理制度
- 觀感質量驗收標準
- 讓流動的花兒綻放-潁泉區北京路一小“關愛流動兒童”案例
- 財務會計工作計劃 (五)
- 課程建設方案
- 行政監督之案例分析
- VMware虛擬化成功案例
- 第一講 案例(中國好聲音 餐飲團購)
- 渣土倒運土票
- 2022年ICD-10惡性腫瘤編碼整理版
- 供貨、安裝進度計劃及保證措施方案
- 劍橋少兒英語一級試題及答案
- 銅桿生產線設備安裝工程施工方案62p
- 連續壓機生產刨花板熱壓質量控制初探.pdf
- 發電廠的電氣部分課程設計
- (自己編)絲網除沫器計算
- 負壓氣力輸送系統
- 國內蒸汽節能背景和蒸汽系統現狀
- 小學二年級下冊道德與法治-11我是一張紙-部編ppt課件
評論
0/150
提交評論