基于Java的網(wǎng)上書城的設(shè)計(jì)與實(shí)現(xiàn)(完整資料)_第1頁
基于Java的網(wǎng)上書城的設(shè)計(jì)與實(shí)現(xiàn)(完整資料)_第2頁
基于Java的網(wǎng)上書城的設(shè)計(jì)與實(shí)現(xiàn)(完整資料)_第3頁
基于Java的網(wǎng)上書城的設(shè)計(jì)與實(shí)現(xiàn)(完整資料)_第4頁
基于Java的網(wǎng)上書城的設(shè)計(jì)與實(shí)現(xiàn)(完整資料)_第5頁
已閱讀5頁,還剩189頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

基于Java的網(wǎng)上書城的設(shè)計(jì)與實(shí)現(xiàn)(完整資料)(可以直接使用,可編輯優(yōu)秀版資料,歡迎下載)

編號(hào):1351101105基于Java的網(wǎng)上書城的設(shè)計(jì)與實(shí)現(xiàn)(完整資料)(可以直接使用,可編輯優(yōu)秀版資料,歡迎下載)畢業(yè)設(shè)計(jì)(2017屆本科)題目:基于Java的網(wǎng)上書城的設(shè)計(jì)與實(shí)現(xiàn)系(部)院:信息技術(shù)與傳媒學(xué)院專業(yè):計(jì)算機(jī)科學(xué)與技術(shù)作者姓名:陳衛(wèi)國指導(dǎo)教師:祁金佺職稱:講師完成日期:2017年5月15日河西學(xué)院本科生畢業(yè)論文(設(shè)計(jì))誠信聲明本人鄭重聲明:所呈交的本科畢業(yè)論文(設(shè)計(jì)),是本人在指導(dǎo)老師的指導(dǎo)下,獨(dú)立進(jìn)行研究(設(shè)計(jì)開發(fā))工作所取得的成果,成果不存在知識(shí)產(chǎn)權(quán)爭(zhēng)議,除文中已經(jīng)注明引用的內(nèi)容外,本論文不含任何其他個(gè)人或集體已經(jīng)發(fā)表或撰寫過的作品成果.對(duì)本文的研究做出重要貢獻(xiàn)的個(gè)人和集體均已在文中以明確方式標(biāo)明。本人完全意識(shí)到本聲明的法律結(jié)果由本人承擔(dān)。本科畢業(yè)論文(設(shè)計(jì))作者簽名:摘要進(jìn)入二十一世紀(jì),電子商務(wù)已經(jīng)逐漸成為主流的商業(yè)模式,“當(dāng)當(dāng)”、“京東”和“淘寶”演變成為我們生活中的一部分、一種生活的習(xí)慣.隨著IT技術(shù)的進(jìn)步和發(fā)展,網(wǎng)上書城已經(jīng)成為一種新型的圖書銷售形式。本文綜合分析了網(wǎng)上書城的用戶需求和系統(tǒng)業(yè)務(wù)流程,并針對(duì)分析和具體設(shè)計(jì)等進(jìn)行了詳細(xì)的介紹.該系統(tǒng)通過分析客戶的需求,確定了系統(tǒng)的功能模塊,將網(wǎng)上書城功能模塊分成兩部分,即前臺(tái)功能管理模塊和后臺(tái)功能管理模塊。前臺(tái)功能管理模塊,實(shí)現(xiàn)了首頁展示、商城公告、銷售排行、圖書分類、購物車、訂單生成等主要功能;后臺(tái)管理模塊,實(shí)現(xiàn)了后臺(tái)登錄功能、圖書管理功能、用戶管理功能、前臺(tái)管理和訂單管理功能等。通過實(shí)現(xiàn)這些模塊,用戶可以很方便的實(shí)現(xiàn)網(wǎng)上購書的目的和管理員對(duì)書城更好的管理。本系統(tǒng)采用了目前成熟完善的技術(shù)體系。開發(fā)平臺(tái)選用基于Java語言的MyEclipse,實(shí)現(xiàn)方式采用B/S架構(gòu),系統(tǒng)遵循J2EE模型體系和MVC設(shè)計(jì)模式,關(guān)鍵技術(shù)上選用目前Web系統(tǒng)主流的“Struts+Spring+Hibernat(yī)e”開發(fā)手段.關(guān)鍵詞:網(wǎng)上書城;電子商務(wù);JSP;SSH;MVCAbstractE—commercehasgraduallybecomethemainstreambusinessmodelintwenty-firstCentury.E-platformslikeDangdang,JingdongandTaobaoplaysanessentialroleinourlife.Ontheconsequence,onlineshoppinghasbeenanormallifestyle.WithdevelopmentofITtechnology,onlinebookstoreshasbecomeanewapproachtobooksales.Thispaperanalysesusers’needsoftheonlinebookstoresaswellastheprocessesofsystemservice.Focusingoncomprehensiveanalysesandspecificdesigns,thethesisprovidesadetailedintroduction.Fromtheanalysesofusers’needs,thesystemdeterminestwofunctionmodules,namelythefrontdeskmanagementfunctionmoduleandthebackstagemanagementfunctionmodule。Thefrontdeskthemanagementfunctionmodulehavethefollowingparts:homepagedisplayandkeyrecommendation,onlineannouncement,salesrank,bookclassificat(yī)ion,shoppingcartandorders。Whilethebackstagemanagementmodulecoverfunctionsofthebackendlogin,booksmanagement,usermanagement,andordermanagement.Throughtheeffectiveoperationofthesemodules,usersareeasilyablechooseandbuybooksonlinewhiletheadministratorcanmanagethewebsitemoreefficiently.Thesystemadoptsadvancedanddevelopedtechnology.Theplat(yī)formemploysMyEclipsebasedonJavalanguagetousetheB/Sstructure.ThesystemfollowstheJ2EEsystemandtheMVCpattern.Referringthekeytechnology,thepopulartool,"Struts+Spring+Hibernate"inwebsystem,iswidelyused。Keywords:Onlinebookstore;E–commerce;JSP;SSH;MVC目錄TO(shè)C\o"1—3"\h\z\uHYPERLINK\l_Toc31476第一章設(shè)計(jì)概述PAGEREF_Toc3147611.1設(shè)計(jì)背景與意義PAGEREF_Toc238201HYPERLINK\l_Toc111311。2同類或相關(guān)系統(tǒng)的開發(fā)現(xiàn)狀PAGEREF_Toc1113111。3選題的主要工作內(nèi)容[14]。下面是以用戶登錄模塊來簡(jiǎn)單介紹一下測(cè)試.如圖6-1、圖6-2所示。12123456圖6-2登錄模塊流圖NoYes輸入用戶名和密碼登錄是否正確登錄開始結(jié)束登錄成功圖6-1登錄模塊流程圖根據(jù)流圖確定環(huán)形復(fù)雜性度量V(G),可以用三種方法求出V(G)的值:1.V(G)=邊數(shù)—結(jié)點(diǎn)數(shù)+2=6—6+2=2。2.V(G)=2(個(gè)區(qū)域)。3.V(G)=謂詞結(jié)點(diǎn)個(gè)數(shù)+1=1+1=2。根據(jù)路徑設(shè)計(jì)相應(yīng)的測(cè)試用例:路徑1:測(cè)試步驟:輸入正確的用戶名和密碼預(yù)期結(jié)果:用戶成功登錄。實(shí)際結(jié)果:登錄成功。路徑2:測(cè)試步驟1:輸入錯(cuò)誤的用戶名或密碼預(yù)期結(jié)果:輸入錯(cuò)誤,返回到輸入用戶名和密碼實(shí)際結(jié)果:登錄失敗。測(cè)試步驟2:不輸入用戶名和密碼預(yù)期結(jié)果:輸入錯(cuò)誤,返回到輸入用戶名和密碼實(shí)際結(jié)果:登錄失敗.6。2。2測(cè)試總結(jié)該系統(tǒng)在測(cè)試過程中遇到了許多問題,像數(shù)據(jù)庫的連接,各界面之間的轉(zhuǎn)化不流暢,各個(gè)功能點(diǎn)的實(shí)現(xiàn)等。通過系統(tǒng)測(cè)試,逐步的解決了各種問題,使系統(tǒng)能夠穩(wěn)定的運(yùn)行,達(dá)到了預(yù)期的效果。結(jié)論本次畢業(yè)設(shè)計(jì)的即時(shí)聊天系統(tǒng),主要是以學(xué)習(xí)研究為目的,所有實(shí)現(xiàn)的功能都是最基本的。盡管這樣,我還是做了很多準(zhǔn)備工作,搜集了相關(guān)論文,參閱了相關(guān)書籍.由于系統(tǒng)界面設(shè)計(jì)較為繁雜,不像之前用Visual

Studio可以拖控件,界面很快搞定,所以初期花費(fèi)了不少時(shí)間去了解Java界面開發(fā)相關(guān)知識(shí)。這種搜集和學(xué)習(xí)相關(guān)知識(shí)的方法和經(jīng)歷對(duì)自己以后做課題研究有很大的啟發(fā)意義.

在進(jìn)行系統(tǒng)的分析與設(shè)計(jì)中我熟悉了從現(xiàn)狀描述到系統(tǒng)建模以及系統(tǒng)實(shí)現(xiàn)的整個(gè)過程,這將自己以前在課堂上所學(xué)的基礎(chǔ)知識(shí)及課外所學(xué)的知識(shí)串連起來,綜合應(yīng)用到一個(gè)真實(shí)的系統(tǒng)中去。編制系統(tǒng)開發(fā)計(jì)劃使自己對(duì)分析設(shè)計(jì)的所有工作和進(jìn)度有了清楚的了解。我深刻地認(rèn)識(shí)到系統(tǒng)的可行性分析十分重要,這將決定系統(tǒng)的開發(fā)價(jià)值。如何實(shí)現(xiàn)服務(wù)器和客戶端的通訊是本系統(tǒng)分析的重頭,通過參考多位業(yè)界知名Java講師的著作,我理解了如何用Java實(shí)現(xiàn)網(wǎng)絡(luò)通信。然后將其轉(zhuǎn)化為數(shù)據(jù)流程圖,使自己理清了系統(tǒng)的工作思路,對(duì)于系統(tǒng)的流程有了清楚的把握.數(shù)據(jù)庫的設(shè)計(jì)使自己學(xué)會(huì)了如何分析用戶的需求,設(shè)計(jì)出合理規(guī)范的數(shù)據(jù)庫。數(shù)據(jù)庫設(shè)計(jì)是系統(tǒng)實(shí)施的一個(gè)基礎(chǔ),是整個(gè)系統(tǒng)后臺(tái)的支撐。系統(tǒng)開發(fā)過程中我學(xué)習(xí)了使用MySQL進(jìn)行數(shù)據(jù)庫建表的相關(guān)知識(shí),受益很多。

本系統(tǒng)采用免費(fèi)開源的MyEclipse開發(fā),由于時(shí)間有限,只開發(fā)了登錄、注冊(cè)、文字聊天、后臺(tái)管理四個(gè)模塊,通過動(dòng)手編程使自己又重新回顧了Java語言的相關(guān)知識(shí),熟悉了操作平臺(tái)。在本系統(tǒng)開發(fā)的開發(fā)過程中我遇到了一些棘手問題,每遇到一個(gè)問題,我都想辦法去解決,在這個(gè)過程中我充分利用了網(wǎng)絡(luò)資源。有時(shí)在IT技術(shù)論壇CSDN論壇上發(fā)帖求助,也因此了解了一些論壇牛人,學(xué)到了不少知識(shí)。經(jīng)過我的鉆研,有的問題已經(jīng)解決但還有一些期待實(shí)現(xiàn)。

成功解決的問題:

1、服務(wù)器端如何處理客戶端的不同請(qǐng)求。客戶端有時(shí)是請(qǐng)求登錄驗(yàn)證,有時(shí)是請(qǐng)求返回好友列表,有時(shí)是請(qǐng)求發(fā)送文字消息給對(duì)方.開始的時(shí)候不知道怎么去做,然后查詢了相關(guān)資料,參照別人的做法,設(shè)計(jì)了一個(gè)Message類,這個(gè)類不僅僅是字面意思消息,它是服務(wù)器客戶端通信的實(shí)體,不管是聊天消息還是登錄請(qǐng)求,任何服務(wù)器客戶端的通信都封裝成Message發(fā)送,接收方收到后根據(jù)Message對(duì)象的屬性自行判斷是何種消息,然后做相應(yīng)處理.

2、離線消息推送.給不在線的人也應(yīng)該能發(fā)送消息,但是對(duì)方如何接收到呢?這個(gè)問題我是這樣解決的。凡是給不在線好友發(fā)送消息,統(tǒng)一寫入數(shù)據(jù)庫。每次客戶端用戶登錄,首先執(zhí)行一條線程,這條線程用來檢測(cè)數(shù)據(jù)庫msg表是否存在內(nèi)容,有的話就按照發(fā)送方接收方推送給指定用戶,然后刪除數(shù)據(jù)庫的離線消息.這個(gè)方法雖然笨了點(diǎn),有冗余的操作,但是功能實(shí)現(xiàn)了。

期待解決的問題:

完成用戶隱身登錄不影響消息接收及記住密碼自動(dòng)登錄的功能.

保存任何用戶的聊天記錄,并以加密的形式存儲(chǔ)在數(shù)據(jù)庫中。

如何將不同格式的文件發(fā)送給對(duì)方讓我一籌莫展。

當(dāng)然功能越想越多,有的是技術(shù)問題,有的是時(shí)間問題,總而言之期待以后完善.

本科畢業(yè)設(shè)計(jì)是對(duì)自己四年所學(xué)的一次綜合性檢驗(yàn),雖然在做畢業(yè)設(shè)計(jì)的過程中遇到很多困難,但通過上網(wǎng)和查書解決了很多從未遇到過的問題,感覺很有成就感。這次的畢業(yè)設(shè)計(jì)確實(shí)讓我學(xué)到了很多知識(shí).最大的感概就是系統(tǒng)開發(fā)之前的設(shè)計(jì)是尤為重要的,這決定了系統(tǒng)開發(fā)的工程量、效率。設(shè)計(jì)能力才是檢驗(yàn)一個(gè)軟件工程師水平的指標(biāo)。站在軟件開發(fā)技術(shù)金字塔頂端的往往是那些資深的系統(tǒng)架構(gòu)師,這應(yīng)當(dāng)成為我的奮斗目標(biāo)!大學(xué)里學(xué)的課程如數(shù)據(jù)結(jié)構(gòu)與算法、計(jì)算機(jī)組成原理、操作系統(tǒng)等課程正是為我們走向“金字塔"鋪路的,只有基本功扎實(shí)才能在IT技術(shù)領(lǐng)域游刃有余。致謝歷時(shí)半載,從論文選題到搜集資料,從完成開題報(bào)告到寫初稿,再經(jīng)過反復(fù)修改,直至最終成型,這期間經(jīng)歷了喜悅、聒噪、痛苦和彷徨,在寫作論文的過程中心情是如此復(fù)雜。如今,伴隨著這篇畢業(yè)論文的最終成稿,復(fù)雜的心情煙消云散,自己甚至還有一點(diǎn)成就感。對(duì)于本篇畢業(yè)論文的寫作,我得到了很多老師和同學(xué)的幫助,其中我的論文指導(dǎo)老師范忠誠老師對(duì)我的指導(dǎo)和幫助尤為重要。在我做畢業(yè)設(shè)計(jì)的每個(gè)階段,從選題到查閱資料,再到論文提綱的確定,中期論文的修改,后期論文格式調(diào)整等各個(gè)環(huán)節(jié)中,范老師都給予了我悉心的指導(dǎo)。在這幾個(gè)月的相處中,范老師給予我的不僅僅是在論文寫作方面的幫助,他廣博的學(xué)識(shí)、深厚的學(xué)術(shù)素養(yǎng)、嚴(yán)謹(jǐn)?shù)闹螌W(xué)精神和一絲不茍的工作作風(fēng)也給我留下了深刻的印象,讓我受益終生。在此謹(jǐn)向范忠誠老師致以誠摯的謝意和崇高的敬意。同時(shí),本篇畢業(yè)論文的寫作也得到了李杭、張阿飛等同學(xué)的熱情幫助,感謝在整個(gè)畢業(yè)設(shè)計(jì)期間給予我?guī)椭耐瑢W(xué),以及曾經(jīng)在各個(gè)方面給予過我?guī)椭幕锇閭?,是他們彌補(bǔ)了我在部分方面知識(shí)的匱乏,從而加快了本篇論文的進(jìn)展,幫助我如期完成自己的畢業(yè)論文。伴隨著本片論文的落稿,大學(xué)四年學(xué)習(xí)時(shí)光也已經(jīng)接近尾聲,在此我想對(duì)我的母校、我的老師、我的同學(xué)以及我的父母和親人們表達(dá)我由衷的謝意.參考文獻(xiàn)[1]印旻,王行言.Java語言與面向?qū)ο蟪绦蛟O(shè)計(jì)(第二版)[M].北京:清華大學(xué)出版社,2007.11

。[2](美)馬勞克林.深入淺出Ajax(中文版)[M]。南京:南京大學(xué)出版社,2008。[3]李剛。輕量級(jí)JavaEE企業(yè)應(yīng)用實(shí)戰(zhàn)——Struts2+Spring+Hibernate整合開發(fā)[M]。北京:電子工業(yè)出版社,2008.[4]熊曉敏,陳惠清.基于Java的網(wǎng)絡(luò)即時(shí)通訊系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)[J]。計(jì)算機(jī)與現(xiàn)代化,2005。12。[5]羅軍舟,黃健.TCP/IP協(xié)議及網(wǎng)絡(luò)編程技術(shù)[M].北京:清華大學(xué)出版社,2005.8。[6](美)鮑格斯坦(Bergsten,H。)著,林琪,朱濤江譯.JSP設(shè)計(jì)(第三版)ReillyJava系列[M]。北京:中國電力出版社,2004。[7]王國輝,王易。JSP數(shù)據(jù)庫系統(tǒng)開發(fā)案例精選[M]。北京:人民郵電出版社,2006.[8]孫衛(wèi)琴。Java網(wǎng)絡(luò)編程精解[M]。北京:電子工業(yè)出版社,2007.03。[9]張虹。軟件工程與軟件開發(fā)工具[M].北京:清華大學(xué)出版社,2004.1。[10]BrueeEekel。ThinkingInJava(第三版)[M]。北京:機(jī)械工業(yè)出版社,2005。2。[11]DavidGallardo.SpringinAction[J].ACMcomputingsurveys,2005。[12]ThomasM.Connolly,CarolynE。Eegg著,何玉潔,黃婷兒譯。數(shù)據(jù)庫設(shè)計(jì)教程第2版[M].北京:機(jī)械工業(yè)出版社,2005。[13](美)Roger

S.Pressman

著,鄭人杰,馬素霞

等譯.軟件工程:實(shí)踐者的研究方法[M]。北京:機(jī)械工業(yè)出版社,2011.08。

[14]錢樂秋,朱軍鈺.軟件工程[M].北京:清華大學(xué)出版社,2006.[15]宮學(xué)生,丁男.移動(dòng)通信軟件框架的設(shè)計(jì)與實(shí)現(xiàn)[J]。計(jì)算機(jī)系統(tǒng)應(yīng)用,2010.05.附錄附錄1:系統(tǒng)的配置與使用1.1硬件條件由于系統(tǒng)主要定位于內(nèi)部局域網(wǎng),計(jì)算機(jī)配置需求不是很高,如下:即時(shí)通信服務(wù)器:50用戶規(guī)模雙CPU:PIV2.4GMHZ以上,內(nèi)存:1G以上??蛻舳耍篊PUPIII2.0以上,內(nèi)存:256M以上.1.2軟件條件即時(shí)通信服務(wù)器:Windows2003。客戶端:操作系統(tǒng)Win98、Win2000、Win2003、WinXP。附錄2:JDK安裝及使用選擇好安裝路徑.安裝到計(jì)算機(jī)上。下來進(jìn)行一些設(shè)置。首先右鍵點(diǎn)我的電腦.打開屬性.然后選擇“高級(jí)”里面的“環(huán)境變量”,在新的打開界面中的系統(tǒng)變量需要設(shè)置三個(gè)屬性“java_home"、“path"、“classpath”,其中在沒安裝過jdk的環(huán)境下.path屬性是本來存在的.而java_home和classpath是不存在的。首先點(diǎn)“新建”,然后在變量名寫上java_home,顧名其意該變量的含義就是java的安裝路徑,呵呵,然后在變量值寫入剛才安裝的路徑“C:\jdk1.6";其次在系統(tǒng)變量里面找到path,然后點(diǎn)編輯,path變量的含義就是系統(tǒng)在任何路徑下都可以識(shí)別java命令,則變量值為“%java_home%\bin;%java_home%\jre\bin",(其中“%java_home%"的意思為剛才設(shè)置java_home的值),也可以直接寫上“C:\jdk1。6\bin";最后再點(diǎn)“新建”,然后在變量名上寫classpath,該變量的含義是為java加載類(classorlib)路徑,只有類在classpath中,java命令才能識(shí)別。其值為“。;%java_home%\lib;%java_home%\lib\tools。jar(要加.表示當(dāng)前路徑)",與相同“%java_home%有相同意思”。以上三個(gè)變量設(shè)置完畢,則按“確定"直至屬性窗口消失,下來是驗(yàn)證看看安裝是否成功.先打開“開始”-〉“運(yùn)行”,打入“cmd”,進(jìn)入dos系統(tǒng)界面.然后打“java—version”,如果安裝成功.系統(tǒng)會(huì)顯示javaversionjdk””。確保安裝在C盤文件名為jdk1。6,環(huán)境變量直接復(fù)制就可以了。附錄3:服務(wù)器端安裝及使用首先,將系統(tǒng)存放到C:\CHAT目錄下;然后,在安裝完JDK后,對(duì)系統(tǒng)進(jìn)行配置,注要是將path路徑制定到chat中的存儲(chǔ)路徑;最后:“開始"-〉“運(yùn)行”,打入“cmd”,進(jìn)入dos系統(tǒng)界面.然后輸入cdc:\chat\src\org\seler\service\AppServer。java。附錄4:使用手冊(cè)4.1服務(wù)器端安裝服務(wù)器,并運(yùn)行服務(wù)器;4.2客戶端安裝客戶端,并運(yùn)行客戶端;用戶注冊(cè):其中要求輸入用戶昵稱,性別,年齡,用戶密碼以及郵箱,其中,昵稱必須唯一值。用戶登錄:打開客戶端,輸入用戶名和密碼,點(diǎn)擊“登錄”;用戶聊天:在“聊天內(nèi)容"對(duì)應(yīng)的文本框中,輸入聊天信息,在“你對(duì)"聊天對(duì)象下拉菜單中選擇聊天對(duì)象,最后點(diǎn)擊“發(fā)送"按鈕;信息查看:在“聊天信息"文本框中,查看聊天信息.保存聊天記錄:點(diǎn)擊“保存”,則將聊天信息保存在客戶端中;用戶退出:點(diǎn)擊“退出”。附錄5:程序源代碼(1)JQ客戶端主程序類。packageclient;importjava。awt.Font;importjava。awt。FontFormatException;importjava。io.BufferedInputStream;importjava.io.File;importjava.io.IOException;importtools.SetFont;importclient.frm。LoginPane;publicclassJQClient{/***JQ客戶端主程序類?!碽r〉*加載字體到UIManager,啟動(dòng)登陸窗口。*/publicstaticvoidmain(String[]args){try{Fontfont=Font.createFont(Font.TRUETYPE_FONT,newBufferedInputStream(JQClient。class。getResourceAsStream("/tools/simsun。ttc")));font=font.deriveFont(Font.PLAIN,12);SetFont.setFont(font);}catch(FontFormatExceptione){System.out.println("錯(cuò)誤:"+e.getMessage());}catch(IOExceptione){System.out.println(”錯(cuò)誤:”+e。getMessage());}newLoginPane();}}(2)登錄面板類packageclient.frm;publicclassLoginPaneextendsJFrameimplementsActionListener{privateJLabellblImg=newJLabel();privateJLabellblJQNum=newJLabel(”JQ賬號(hào)");privateJComboBoxboxJQNum=newJComboBox();privateJLabellblPassword=newJLabel("JQ密碼”);privateJPasswordFieldpfPassword=newJPasswordField();privateJLabellblState=newJLabel(”狀態(tài):");privateJComboBoxboxState=newJComboBox();privateJCheckBoxboxAutoLogin=newJCheckBox(”自動(dòng)登錄");privateJButtonbtnRegister=newJButton("申請(qǐng)賬號(hào)”);privateJButtonbtnSet=newJButton(”設(shè)置↓”);privateJButtonbtnLogin=newJButton(”登錄”);privateJLabellblServerIP=newJLabel(”服務(wù)器IP:");privateJTextFieldtxtServerIP=newJTextField("127.0.0。1”);privateJLabellblServerPort=newJLabel("端口:");privateJTextFieldtxtServerPort=newJTextField(”3608");prjavax.swing。JButton;publicLoginPane(){setTitle("JQ用戶登錄");setSize(324,235);setResizable(false);Toolkittk=Toolkit.getDefaultToolkit();setLocation((tk。getScreenSize().width-getSize()。width)/2,(tk。getScreenSize()。height—getSize()。height)/2);setBackground(newColor(224,244,251));init();btnLogin。addActionListener(this);btnRegister。addActionListener(this);btnSet。addActionListener(this);setDefaultCloseOperation(EXIT_ON_CLOSE);setVisible(true);}privatevoidinit(){lblImg.setIcon(newImageIcon(LoginPane.class。getResource(”/client/images/top。gif”)));lblImg.setPreferredSize(newDimension(325,47));boxState.addItem(UserState.ONLINESTATE);boxState.addItem(UserState.HIDDENSTATE);boxState。addItem(UserState.DEPARTURESTATE);boxState.addItem(UserState。BUSYSTATE);boxState。setBackground(newColor(240,250,255));boxState.setPreferredSize(newDimension(60,20));boxAutoLogin。setBackground(newColor(240,250,255));boxJQNum。setEditable(true);boxJQNum。setPreferredSize(newDimension(140,20));pfPassword.setPreferredSize(newDimension(140,20));txtServerIP.setPreferredSize(newDimension(80,20));txtServerPort。setPreferredSize(newDimension(50,20));JPanelpane=newJPanel();pane.setBackground(newColor(240,250,255));pane.setBorder(newLineBorder(newColor(144,185,215)));pane.setLayout(newFlowLayout(FlowLayout.CENTER,15,12));pane。setPreferredSize(newDimension(300,110));pane。add(newFillWidth(20,20,newColor(240,250,255)));pane.add(lblJQNum);pane。add(boxJQNum);pane.add(newFillWidth(20,20,newColor(240,250,255)));pane。add(newFillWidth(20,20,newColor(240,250,255)));pane。add(lblPassword);pane。add(pfPassword);pane.add(newFillWidth(20,20,newColor(240,250,255)));pane。add(lblState);pane.add(boxState);pane.add(boxAutoLogin);TitledBordertb=newTitledBorder(newLineBorder(Color.GRAY),"網(wǎng)絡(luò)設(shè)置”);JPanelpaneSet=newJPanel();paneSet。setPreferredSize(newDimension(300,60));paneSet.setBorder(tb);paneSet。add(lblServerIP);paneSet。add(txtServerIP);paneSet。add(newFillWidth(30,20));paneSet。add(lblServerPort);paneSet.add(txtServerPort);setLayout(newFlowLayout(FlowLayout.CENTER,5,0));add(lblImg);add(newFillWidth(100,8));add(pane);add(newFillWidth(300,8));add(btnRegister);add(btnSet);add(newFillWidth(65,20));add(btnLogin);add(newFillWidth(300,8));add(paneSet);}/***設(shè)置按鈕、登陸按鈕、注冊(cè)按鈕的事件。*/publicvoidactionPerformed(ActionEvente){if(e.getSource()==btnSet){if(isSet){isSet=false;setSize(getWidth(),getHeight()-65);btnSet。setText(”設(shè)置↓");}else{isSet=true;setSize(getWidth(),getHeight()+65);btnSet。setText("設(shè)置↑”);}}if(e.getSource()==btnLogin){dispose();newMainPane(txtServerIP.getText(),Integer.parseInt(txtServerPort.getText()),Integer。parseInt(boxJQNum.getSelectedItem().toString()),newString(pfPassword。getPassword()),((UserState)boxState。getSelectedItem()).getState());}if(e。getSource()==btnRegister){dispose();newRegisterPane();}}}(3)主程序類、JQ的主框架類。publicclassMainPaneextendsJFrameimplementsActionListener{privateJLabellblPhoto=newJLabel();privateJComboBoxboxState=newJComboBox();privateJLabellblNickName=newJLabel();privateJTextAreatxtSignature=newJTextArea();privateJListlistFriend;//=newJList();privateDefaultListModellistModel=null;privateJButtonbtnMenu=newJButton(”菜單”);privateJButtonbtnFind=newJButton("查找”);privateJButtonbtnSys=newJButton(”系統(tǒng)消息");privateJLabellblLoginBar=newJLabel();privateJButtonbtnCancleLogin=newJButton("取消登錄");privateJPanelfillWidth=newFillWidth(118,120,Color.WHITE);privateSocketclient=null;privateObjectOutputStreamoos=null;privateObjectInputStreamois=null;privateHashMap<Integer,ChatPane>chat=null;privateFriendUserselfUser=null;privateStringserverIp;privateIntegerserverPort;privateIntegerjqnum;privateStringpassword;privateIntegerstate;privateJPopupMenupopupMenu=null;privateJMenuItemitemChat=null;privateJMenuItemitemDelete=null;privateJMenuItemitemFriendInfo=null;privateJMenuItemitemLog=null;privateFindWindowfindWindow=null;privateJPopupMenumenu=newJPopupMenu();privateJMenuItemitemQuit=newJMenuItem("退出”);privateBroadcastwindowbroadcastwindow=null;privateThreadthread=null;/***登陸后顯示的主面板的構(gòu)造函數(shù)。*@paramserverIp服務(wù)器ip。*@paramserverPort服務(wù)器端口。*@paramjqnum登陸的jq號(hào)碼。*@parampassword登陸的jq密碼。*@paramstate登陸的狀態(tài).*/publicMainPane(StringserverIp,IntegerserverPort,Integerjqnum,Stringpassword,Integerstate){this。serverIp=serverIp;this.serverPort=serverPort;this.jqnum=jqnum;this.password=password;this.state=state;//System。out。println(jqnum+":"+password+”State:”+state);setTitle(”JQ2016");setSize(200,550);setResizable(false);Toolkittk=Toolkit。getDefaultToolkit();setLocation((tk。getScreenSize()。width—getSize()。width)-10,(tk.getScreenSize()。height—getSize().height)/2-30);//init();getContentPane()。setBackground(Color。WHITE);initLoginPane();//setDefaultCloseOperation(EXIT_ON_CLOSE);setVisible(true);thread=newLoginThread();thread.start();}/***初始化用戶按下登陸按鈕后,主面板顯示登陸進(jìn)度條窗體。*/privatevoidinitLoginPane(){btnCancleLogin.setPreferredSize(newDimension(60,20));btnCancleLogin.setMargin(newInsets(0,0,0,0));btnCancleLogin。setFocusPainted(false);lblLoginBar。setIcon(newImageIcon(MainPane.class.getResource(”/client/images/loginbar。gif")));setLayout(newFlowLayout(FlowLayout.CENTER,20,10));add(fillWidth);add(lblLoginBar);//add(newFillWidth(1,2,Color.WHITE));add(btnCancleLogin);btnCancleLogin.addActionListener(this);//initMain();}/***初始化用戶登陸成功后,顯示主窗體。*@paramv好友列表.*/privatevoidinitMain(Vector〈FriendUser〉v){newMSG(25);selfUser=v。get(0);v。remove(0);setTitle("JQ2016"+selfUser.getJqnum());popupMenu=newJPopupMenu();itemChat=newJMenuItem(”發(fā)送即時(shí)消息");itemDelete=newJMenuItem(”刪除該好友”);itemFriendInfo=newJMenuItem("查看好友資料");itemLog=newJMenuItem("聊天記錄");popupMenu。add(itemChat);popupMenu.add(itemFriendInfo);popupMenu。addSeparator();popupMenu。add(itemLog);popupMenu。addSeparator();popupMenu。add(itemDelete);menu.add(newJMenuItem(”設(shè)置”));menu。addSeparator();menu.add(newJMenuItem("幫助"));menu。addSeparator();menu.add(itemQuit);itemQuit。addActionListener(this);btnMenu.addMouseListener(newListMouseAdapter());itemChat。addActionListener(this);itemDelete.addActionListener(this);itemFriendInfo.addActionListener(this);itemLog.addActionListener(this);btnMenu。setMargin(newInsets(0,5,0,5));btnFind。setMargin(newInsets(0,5,0,5));btnFind.addActionListener(this);btnSys。setMargin(newInsets(0,5,0,5));btnSys.addMouseListener(newListMouseAdapter());lblPhoto。setSize(50,50);lblPhoto.setLocation(5,5);lblPhoto。setOpaque(true);lblPhoto.setBackground(newColor(116,220,253,150));lblPhoto.setHorizontalAlignment(SwingConstants。CENTER);lblPhoto。setIcon(newPortrait(selfUser。getPhoto(),selfUser。getState()));lblPhoto。setBorder(newLineBorder(newColor(60,168,206),1,true))boxState。setSize(50,20);boxState。setLocation(60,5);boxState.addItem(UserState.ONLINESTATE);boxState。addItem(UserState。HIDDENSTATE);boxState。addItem(UserState。DEPARTURESTATE);boxState.addItem(UserState.BUSYSTATE);boxState。setSelectedIndex(selfUser。getState());lblNickName。setSize(80,20);lblNickName.setLocation(115,5);lblNickName.setText(selfUser.getNickName()+"[”+UserState.getStateName(selfUser.getState())+"]");txtSignature。setText(selfUser。getSignature());txtSignature。setEditable(false);txtSignature。setLineWrap(true);txtSignature.setBackground(getBackground());JScrollPanespSign=newJScrollPane(txtSignature);spSign.setSize(125,25);spSign。setLocation(60,30);spSign。setBorder(newEmptyBorder(newInsets(0,0,0,0)));JPanelpaneTop=newJPanel();paneTop。setLayout(null);paneTop.setPreferredSize(newDimension(200,60));paneTop。add(lblPhoto);paneTop.add(boxState);paneTop.add(lblNickName);paneTop.add(spSign);listModel=newDefaultListModel();for(FriendUseruser:v){listModel.addElement(user);}setLayout(newBorderLayout());add(paneTop,BorderLayout。NORTH);add(sp,BorderLayout。CENTER);add(newFillWidth(5,5),BorderLayout.EAST);add(newFillWidth(5,5),BorderLayout。WEST);add(paneBottom,BorderLayout。SOUTH);setVisible(true);broadcastwindow=newBroadcastwindow();}/***取消按鈕、聊天按鈕、刪除好友、好友按鈕、查找按鈕事件.*/publicvoidactionPerformed(ActionEvente){if(e。getSource()==btnCancleLogin){closeClient();System。exit(0);return;}if(e。getSource()==itemChat){chatWithFriend();return;}if(e。getSource()==itemDelete){JOptionPane。showMessageDialog(null,"功能制作中。。.”);return;}if(e.getSource()==itemFriendInfo){JOptionPane.showMessageDialog(null,”功能制作中。.。”);return;}if(e。getSource()==itemLog){JOptionPane.showMessageDialog(null,”功能制作中...");return;}if(e.getSource()==btnFind){if(findWindow==null)findWindow=newFindWindow(this,false);else{findWindow.setVisible(true);}return;}if(e。getSource()==itemQuit){quit();closeClient();System.exit(0);}}/***根據(jù)好友號(hào)碼獲得listFriendUser中的好友。*@paramjqnum好友的jq號(hào)碼。*@return好友的信息FriendUser類。不存在是返回空。*/privateFriendUsergetFriendUserFromList(intjqnum){for(inti=0;i〈listFriend。getModel()。getSize();i++){Objectobj=listFriend。getModel().getElementAt(i);if(objinstanceofFriendUser){FriendUserfriendUser=(FriendUser)obj;if(friendUser。getJqnum()==jqnum)returnfriendUser;}}returnnull;}/***退出事件.*/privatevoidquit(){JQMessagemessage=newJQMessage();message。setType(24);message.setObj(selfUser);try{oos.writeObject(message);oos.flush();}catch(IOExceptione){e.printStackTrace();}closeClient();errupt();System.exit(0);}/*publicstaticvoidmain(String[]args){try{//System。out.println(JQClient。class.getResource("../tools/simsun.ttc”)。getPath());Fontfont=Font.createFont(Font.TRUETYPE_FONT,newFile(MainPane。class.getResource("/tools/simsun.ttc").getPath()));font=font.deriveFont(Font.PLAIN,12);SetFont.setFont(font);}catch(FontFormatExceptione){System.out。println(”錯(cuò)誤:"+e。getMessage());}catch(IOExceptione){System。out。println(”錯(cuò)誤:”+e.getMessage());}newMainPane(”",0,0,"”,1);}*//***窗體關(guān)閉時(shí)觸發(fā)事件.*/privateclassMyWindowAdapterextendsWindowAdapter{publicvoidwindowClosing(WindowEvente){//super。windowClosing(e);quit();}}/***自己定制的好友類表的ListCellRenderer*/privateclassCompanyLogoListCellRendererextendsDefaultListCellRenderer{publicComponentgetListCellRendererComponent(JListlist,Objectvalue,intindex,booleanisSelected,booleancellHasFocus){ComponentretValue=super。getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);//System。out。println(value。toString());if(valueinstanceofFriendUser){FriendUseruser=(FriendUser)value;setIcon(newPortrait(user.getPhoto(),user。getState()));setToolTipText("<html>"+user。getNickName()+"["+user.getJqnum()+"]"+"<br><fontcolor='red’〉”+user.getSignature()+”〈/font〉〈/html>”);}returnretValue;}}/***鼠標(biāo)事件,完成鼠標(biāo)進(jìn)入好友List中,選中好友,雙擊與好友進(jìn)行聊天等。*/privateclassListMouseAdapterextendsMouseAdapter{publicvoidmouseMoved(MouseEvente){//System。out.println(e.getSource());if(e。getSource()==listFriend){listFriend.clearSelection();intindex=listFriend.locationToIndex(e.getPoint());//System.out.println("index:”+index);listFriend。setSelectedIndex(index);}}publicvoidmouseClicked(MouseEvente){if(e。getSource()==listFriend){if(e.getClickCount()==2){chatWithFriend();}if(e.getButton()==MouseEvent。BUTTON3){popupMenu。show(listFriend,e。getX(),e。getY());}return;}if(e.getSource()==btnMenu){menu。show(btnMenu,e.getX()-25,e。getY()-75);}if(e。getSource()==btnSys){broadcastwindow.showNow();}}}/***打開好友聊天窗口.*/privatevoidchatWithFriend(){Objectobj=listFriend.getSelectedValue();if(objinstanceofFriendUser){FriendUserfriendUser=(FriendUser)obj;intjqnum=friendUser。getJqnum();ChatPanechatPane=chat.get(jqnum);if(chatPane==null){chatPane=newChatPane(oos,friendUser,selfUser,true);chat.put(jqnum,chatPane);}elseif(chatPane。isDisplayable()){chatPane。setFocusable(true);chatPane.setState(NORMAL);}else{chatPane.setVisible(true);}}}/***登陸線程。處理服務(wù)端的信息以及發(fā)送消息到服務(wù)端。*/privateclassLoginThreadextendsThread{publicLoginThread(){try{client=newSocket(serverIp,serverPort);MainPane。this。addWindowListener(newMyWindowAdapter());oos=newObjectOutputStream(newBufferedOutputStream(client.getOutputStream()));LoginUserloginUser=newLoginUser();loginUser.setJqnum(jqnum);loginUser.setPassword(password);loginUser.setState(state);JQMessagemessage=newJQMessage();message.setType(20);message.setObj(loginUser);newWriteThread(message).start();ois=newObjectInputStream(newBufferedInputStream(client.getInputStream()));//oos=newObjectOutputStream(client.getOutputStream());//ois=newObjectInputStream(client.getInputStream());}catch(UnknownHostExceptione){closeClient();JOptionPane。showMessageDialog(null,”請(qǐng)確保輸入的服務(wù)器IP和端口正確!"+e.getMessage());dispose();newLoginPane();}catch(IOExceptione){closeClient();JOptionPane.showMessageDialog(null,”請(qǐng)確保輸入的服務(wù)器IP和端口正確!”+e。getMessage());dispose();newLoginPane();}}publicvoidrun(){try{JQMessagemessage=null;while(ois!=null){Objectobj=ois。readObject();if(objinstanceofJQMessage){message=(JQMessage)obj;inttype=message.getType();switch(type){case21://登陸成功if(message。getObj()instanceofVector){Vector<FriendUser〉v=(Vector)message。getObj();initMain(v);}break;case22://登錄失敗closeClient();JOptionPane。showMessageDialog(null,message。getObj()。toString());dispose();newLoginPane();break;case23://賬號(hào)在別處登錄causeLetClientQuit(message);break;case25://好友上線dealFriendUserLogin(message);break;case31://接收到消息dealRecord(message。getObj(),type);break;case41://接受當(dāng)前在線用戶數(shù)dealOnlineNum(message。getObj());break;case43://接受在線的用戶顯示到table上dealShowOnlineUser(message.getObj());break;case45:JOptionPane。showMessageDialog(null,message。getObj().toString());break;case46:JOptionPane。showMessageDialog(null,message。getObj().toString());break;case90://服務(wù)端退出causeLetClientQuit(message);break;case91:dealBroadcast(message);break;}}}}catch(IOExceptione){System.out.println(”發(fā)生異常:"+e.getMessage());closeClient();JOptionPane。showMessageDialog(null,”和服務(wù)端連接發(fā)生錯(cuò)誤:"+e.getMessage()+",請(qǐng)重新登錄!");System.exit(0);}catch(ClassNotFoundExceptione){System.out。println(”發(fā)生異常:"+e.getMessage());closeClient();JOptionPane。showMessageDialog(null,”和服務(wù)端連接發(fā)生錯(cuò)誤:”+e.getMessage()+",請(qǐng)重新登錄!");System.exit(0);}}}/***處理廣播。*@parammessageJQMessage消息對(duì)象。*/privatevoiddealBroadcast(JQMessagemessage){newMSG(message.getType());if(broadcastwindow!=null){broadcastwindow.txt。setText(message.getObj().toString());broadcastwindow.showNow();}}/***有消息來時(shí)出發(fā)聲音.*@paramtype消息的類型。*/privatevoidnewMSG(inttype){//播放*.au文件時(shí)建議使用下面的方法//AudioClipaudioClip=null;//if(n==31)//audioClip=Applet。newAudioClip(MainPane。class。getResource("。。/sound/msg.au”));//if(n==91)//audioClip=Applet.newAudioClip(MainPane.class。getResource(”.。/sound/system.au”));//audioClip。play();//播放*.wav文件時(shí)建議使用下面的方法try{AudioStreamaudioStream=null;switch(type){case25:audioStream=newAudioStream(getClass().getResourceAsStream(”/client/sound/global。wav"));break;case31:audioStream=newAudioStream(getClass()。getResourceAsStream("/client/sound/msg.wav”));break;case91:audioStream=newAudioStream(getClass().getResourceAsStream("/client/sound/system.wav”));break;default:audioStream=newAudioStream(getClass().getResourceAsStream(”/client/sound/msg.wav”));break;}AudioPlayer。player.start(audioStream);}catch(IOExceptione){System.out。println("在播放聲音文件時(shí)[type="+type+"],發(fā)生異常:”+e。getMessage());}}/***處理好友上線時(shí)消息。*@parammessage*/privatevoiddealFriendUserLogin(JQMessagemessage){Objectobj=message.getObj();if(objinstanceofFriendUser){newMSG(message。getType());FriendUserfriendUser=(FriendUser)obj;if(listModel。contains(friendUser)){for(inti=0;i<listModel。getSize();i++){Objectobject=listModel。get(i);if(objectinstanceofFriendUser){FriendUseruser=(FriendUser)object;if(user.equals(friendUser)){user.setState(friendUser。getState());user.setPhoto(friendUser.getPhoto());user.setNickName(friendUser。getNickName());user。setSignature(friendUser。getSignature());listFriend。repaint();break;}}}//更改聊天窗口的圖標(biāo)ChatPanechatPane=chat.get(friendUser.getJqnum());if(chatPane!=null)chatPane。updateFriendPhoto(newPortrait(friendUser。getPhoto(),friendUser.getState(),false));}else{listModel。addElement(friendUser);chat.put(friendUser。getJqnum(),null);listFriend.repaint();}}}/***根據(jù)服務(wù)端發(fā)送的消息,將在線用戶顯示到查找面板上.*@paramobj在線用戶.*/privatevoiddealShowOnlineUser(Objectobj){if(objinstanceofFriendUser)findWindow。addOnlineUser((FriendUser)obj);}/***顯示在線用戶數(shù)到查找面板上。*@paramobj在線用戶數(shù)。*/privatevoiddealOnlineNum(Objectobj){if(objinstanceofInteger){intsize=(Integer)obj;findWindow.lblOnlineNum。setText(”當(dāng)前在線人數(shù):"+size);}}/***處理服務(wù)端發(fā)送的從好友發(fā)過來的消息。*@paramobjRecord對(duì)象。*@paramtype消息類型。*/privatevoiddealRecord(Objectobj,inttype){if(objinstanceofRecord){Recordrecord=(Record)obj;FriendUserfriendUser=getFriendUserFromList(record。getFromid());if(friendUser!=null){newMSG(type);ChatPanechatPane=chat。get(record。getFromid());if(chatPane==null){chatPane=newChatPane(oos,friendUser,selfUser,true);chat.put(friendUser。getJqnum(),chatPane);}elseif(chatPane.isDisplayable()){chatPane。setFocusable(true);chatPane.setState(NORMAL);}else{chatPane.setVisible(true);}chatPane。showRecord(friendUser。getNickName(),record,Color.BLUE);}}}/***因?yàn)槟承┰蚍?wù)端使得客戶端退出。*@parammessage退出的JQMessage對(duì)象。*/privatevoidcauseLetClientQuit(JQMessagemessage){closeClient();JOptionPane.showMessageDialog(null,message。getObj()。toString());System。exit(0);}/***書寫消息線程。*/privateclassWriteThreadextendsThread{privateJQMessagemessage=null;publicWriteThread(JQMessagemessage){this。message=message;}publicvoidrun(){try{if(oos!=null){oos。writeObject(message);oos.flush();}}catch(IOExceptione){System。out。println("發(fā)生異常:"+e.getMessage());closeClient();JOptionPane。showMessageDialog(null,"和服務(wù)端連接發(fā)生錯(cuò)誤:”+e。getMessage()+",請(qǐng)重新登錄!");System.exit(0);}}}/***關(guān)閉到服務(wù)端的連接。*/privatevoidcloseClient(){try{if(oos!=null)oos.close();oos=null;if(ois!=null)ois。close();ois=null;if(client!=null)client。close();client=null;}catch(IOExceptione){System.out。println("錯(cuò)誤:"+e。getMessage());}}/***查找好友窗口.*/privateclassFindWindowextendsJDialogimplementsActionListener{privateJTabbedPanepaneFindWay=newJTabbedPane();privateJPanelpaneBtn=newJPan

溫馨提示

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

評(píng)論

0/150

提交評(píng)論