java課程設(shè)計(jì)報(bào)告-聊天室_第1頁(yè)
java課程設(shè)計(jì)報(bào)告-聊天室_第2頁(yè)
java課程設(shè)計(jì)報(bào)告-聊天室_第3頁(yè)
java課程設(shè)計(jì)報(bào)告-聊天室_第4頁(yè)
java課程設(shè)計(jì)報(bào)告-聊天室_第5頁(yè)
已閱讀5頁(yè),還剩16頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、JAVA程序設(shè)計(jì)課程設(shè)計(jì)報(bào)告班級(jí):(4號(hào)楷體)學(xué)號(hào):(4號(hào)楷體)姓名:(4號(hào)楷體)指導(dǎo)教師:(4 號(hào)楷體)完成日期:2009年 9 月(4號(hào)楷體)課程設(shè)計(jì)報(bào)告書專用紙 題目?jī)?nèi)容的描述本文圍繞Java編程語(yǔ)言在網(wǎng)絡(luò)編程方面的具體應(yīng)用,論述了使用面向?qū)ο蠓椒?,?duì)計(jì)算器程序進(jìn)行需求分析、概要設(shè)計(jì)、詳細(xì)設(shè)計(jì),最后使用Java編程實(shí)現(xiàn)的全過程。在編程我們使用的java語(yǔ)言,是目前比較流行的編程語(yǔ)言。在當(dāng)今這個(gè)網(wǎng)絡(luò)的 時(shí)代,java語(yǔ)言在網(wǎng)絡(luò)編程方面的優(yōu)勢(shì)使得網(wǎng)絡(luò)編程有了更好的選擇。Java語(yǔ)言最大的特點(diǎn)是具有跨平臺(tái)性,使其不受平臺(tái)不同的影響,得到了廣泛的應(yīng)用。二:需求分析1.1 開發(fā)背景:在網(wǎng)絡(luò)越來(lái)越發(fā)

2、達(dá)的今天,人們對(duì)網(wǎng)絡(luò)的依賴越來(lái)越多,越來(lái)越離不開網(wǎng)絡(luò),由此而產(chǎn) 生的聊天工具越來(lái)越多,網(wǎng)絡(luò)聊天時(shí)一類的聊天系統(tǒng)的發(fā)展日新月異,因此產(chǎn)生了制作一個(gè)局域網(wǎng)的網(wǎng)絡(luò)聊天工具的;而且通過制作該程序還能更好的學(xué)習(xí)網(wǎng)絡(luò)軟件編程 知識(shí)1.1 功能要求:(1) 登錄功能(2) 客戶可以通過服務(wù)器轉(zhuǎn)發(fā),實(shí)現(xiàn)一對(duì)一和多對(duì)多聊天(3) 實(shí)現(xiàn)呼叫功能.(4) 客戶端程序應(yīng)該可以實(shí)時(shí)顯示目前其它用戶的狀態(tài).三:主要模塊的算法描述第1頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專用紙四:詳細(xì)設(shè)計(jì)聊天室服務(wù)器端設(shè)計(jì):聊天室服務(wù)端主要包括7個(gè)文件,它們的功能如下:(1) ChatServer.java :包含名為 ChatServer的publi

3、c 類,其主要功能為定 義服務(wù)器端的界面,添加事件偵聽與事件處理。調(diào)用ServerListe n 類來(lái)實(shí)現(xiàn)服務(wù)端用戶上線與下線的偵聽,調(diào)用 ServerReceive類來(lái)實(shí)現(xiàn)服務(wù)器端的消息的收發(fā)。import java.awt.*;import java.awt.eve nt.*;import javax.swi ng.*;import javax.swi ng.eve nt.*;import java .n et.*;import java.io.*;/*聊天服務(wù)端的主框架類*/public class ChatServer exte nds JFrame impleme nts Actio

4、 nListe nerpublic static in t port = 8888;/服務(wù)端的偵聽端口ServerSocket serverSocket;/ 服務(wù)端 SocketImage icon;/程序圖標(biāo)JComboBox combobox;/選擇發(fā)送消息的接受者JTextArea messageShow;/ 服務(wù)端的信息顯示JScrollPa ne messageScrollPa ne;/信息顯示的滾動(dòng)條JTextField showStatus;/顯示用戶連接狀態(tài)JLabel sen dToLabel,messageLabel;JTextField sysMessage;/服務(wù)端消息

5、的發(fā)送JButton sysMessageButt on;/服務(wù)端消息的發(fā)送按鈕UserLi nkList userLi nkList;/用戶鏈表/建立菜單欄JMen uBar jMen uBar = new JMe nuBar();/建立菜單組JMe nu serviceMe nu = new JMe nu ( 服務(wù)(V);/建立菜單項(xiàng)JMenultem portItem = new JMenultem (端口設(shè)置(P),new ImageIcon(face/98.gif);JMenultem startItem= new JMenultem (啟動(dòng)服務(wù)(S),new ImageIcon(f

6、ace/icon.gif);JMe nultemstopItem=newJMe nultem(停止服務(wù)(T), newImageIc on (face/Uabra nd.gif);JMe nultemexitItem=newJMe nultem(退出(X), newImageIc on (face/messe nger_big.gif);JMenu helpMenu=new JMenu (幫助(H);ImageIcon (face/HelpCe nter.gif);JMenultem helpItem=new JMenultem (幫助(H),new/建立工具欄JToolBar toolBar

7、 = new JToolBar();/建立工具欄中的按鈕組件JButton portSet;/JButton startServer;/JButt on stopServer;/JButton exitButt on;/啟動(dòng)服務(wù)端偵聽啟動(dòng)服務(wù)端偵聽 關(guān)閉服務(wù)端偵聽 退出按鈕/框架的大小Dime nsion faceSize = new Dime nsion(400, 600);ServerListen listenThread;JPa nel dow nPanel ;GridBagLayout girdBag;GridBagC on stra ints girdBagC on;/*服務(wù)端構(gòu)造函

8、數(shù)*/public ChatServer()ini t();/初始化程序/添加框架的關(guān)閉事件處理this.setDefaultCloseOperatio n( JFrame.EXIT_ON_CLOSE); this.pack();/設(shè)置框架的大小this.setSize(faceSize);this.setVisible(true);/設(shè)置運(yùn)行時(shí)窗口的位置Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();this.setLocati on( (int) (scree nSize.width - faceSize

9、.getWidth() / 2,(int) (scree nSize.height - faceSize.getHeight() / 2);第6頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專用紙第#頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專用紙this.setResizable(false); this.setTitle(聊天室服務(wù)端 ”);/為服務(wù)菜單欄設(shè)置熱鍵V serviceMe nu.set Mn emo ni c(V);/為端口設(shè)置快捷鍵為ctrl+pportItem.set Mnemonic (P);portItem.setAccelerator(KeyEve nt.VK_P,l nputEve nt.CTRL_MA

10、SK);/為啟動(dòng)服務(wù)快捷鍵為ctrl+sstartItem.set Mn emo nic (S);startItem.setAccelerator(KeyEve nt.VK_S,l nputEve nt.CTRL_MASK);設(shè)置標(biāo)題(KeyStroke.getKeyStroke(KeyStroke.getKeyStroke/為端口設(shè)置快捷鍵為 ctrl+T stopItem.set Mnemonic (T);stopItem.setAccelerator(KeyEve nt.VK_T,l nputEve nt.CTRL_MASK);/為退出設(shè)置快捷鍵為 ctrl+x exitItem.set

11、 Mnemonic (X);exitItem.setAccelerator(KeyEve nt.VK_X,l nputEve nt.CTRL_MASK);(KeyStroke.getKeyStroke(KeyStroke.getKeyStroke/為幫助菜單欄設(shè)置熱鍵H helpMe nu.setM nemo nic(H);/為幫助設(shè)置快捷鍵為 ctrl+p helpItem.set Mnemonic (H);helpItem.setAccelerator(KeyEve nt.VK_H,l nputEve nt.CTRL_MASK);(KeyStroke.getKeyStroke第7頁(yè)共18頁(yè)

12、課程設(shè)計(jì)報(bào)告書專用紙第8頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專用紙*程序初始化函數(shù)*/public void in it()Container conten tPa ne = getC onten tPa ne();conten tPa ne.setLayout (new BorderLayout();/添加菜單欄serviceMe nu .add (portItem); serviceMe nu .add (startItem); serviceMe nu .addSeparator(); serviceMe nu .add (stopItem); serviceMe nu .addSeparator(

13、); serviceMe nu.add (exitItem); jMen uBar.add (serviceMe nu); helpMe nu .add (helpItem); jMe nuBar.add (helpMe nu); setJMe nuBar (jMe nuBar);/初始化按鈕portSet = new JButton(”端口設(shè)置);startServer = new JButton(”啟動(dòng)服務(wù));stopServer = new JButton(”停止服務(wù)”);exitButton = new JButton(”退出”);/將按鈕添加到工具欄toolBar.add(portS

14、et); toolBar.addSeparator();/添加分隔欄toolBar.add(startServer); toolBar.add(stopServer);添加分隔欄toolBar.addSeparator();/ toolBar.add(exitButto n);con te ntPa ne.add(toolBar,BorderLayout.NORTH);/初始時(shí),令停止服務(wù)按鈕不可用stopServer.setE nabled(false); stopItem .setE nabled(false);/為菜單欄添加事件監(jiān)聽portItem.addAct ion Liste ne

15、r(this); startItem.addActi on Liste ner(this); stopItem.addAct ion Liste ner(this); exitItem.addActio nListe ner(this); helpItem.addAct ion Liste ner(this);/添加按鈕的事件偵聽portSet.addAct ion Liste ner(this); startServer.addAct ion Liste ner(this); stopServer.addActi on Liste ner(this); exitButt on. addAct

16、 ion Liste ner(this);combobox = new JComboBox(); combobox.insertltemAt(”所有人,0);combobox.setSelectedI ndex(O);messageShow = new JTextArea(); messageShow.setEditable(false);/添加滾動(dòng)條messageScrollPa ne = new JScrollPa ne(messageShow,JScrollPa ne.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPa ne.HORIZONTAL_SCROLLB

17、AR_AS_NEEDED); messageScrollPa ne.setPreferredSize( new Dime nsion(400,400); messageScrollPa ne.revalidate();showStatus = new JTextField(35); showStatus.setEditable(false);sysMessage = new JTextField(24); sysMessage.setE nabled(false); sysMessageButt on = new JButt on(); sysMessageButton.setText(”發(fā)送

18、);/添加系統(tǒng)消息的事件偵聽sysMessage.addAct ion Liste ner(this); sysMessageButt on. addActi on Liste ner(this);sendToLabel = new JLabel(發(fā)送至:);messageLabel = new JLabel( 發(fā)送消息:); dow nPanel = new JPa nel();girdBag = new GridBagLayout();dow nPan el.setLayout(girdBag);girdBagC on = new GridBagC on stra in ts(); gir

19、dBagC on. gridx = 0;girdBagC on. gridy = 0;girdBagC on. gridwidth = 3;girdBagC on. gridheight = 2;girdBagC on .ipadx = 5;girdBagC on .ipady = 5;JLabel none = new JLabel( ); girdBag.setC on stra ints(non e,girdBagC on);dow nPan el.add( non e);girdBagC on = new GridBagC on stra in ts();girdBagC on. gr

20、idx = 0;girdBagC on. gridy = 2;girdBagC on .i nsets = new In sets(1,O,O,O);girdBagC on .ipadx = 5;girdBagC on .ipady = 5;girdBag.setC on stra in ts(se ndToLabel,girdBagC on);dow nPan el.add(se ndToLabel);girdBagC on = new GridBagC on stra in ts();girdBagC on. gridx =1;girdBagC on. gridy = 2;girdBagC

21、o n.anchor = GridBagCo nstrai nts. LINE_START;girdBag.setC on stra in ts(combobox,girdBagC on);dow nPan el.add(combobox);girdBagC on = new GridBagC on stra in ts();girdBagC on. gridx = 0;girdBagC on. gridy = 3;girdBag.setC on stra in ts(messageLabel,girdBagC on);dow nPan el.add(messageLabel);girdBag

22、C on = new GridBagC on stra in ts();girdBagC on. gridx = 1;girdBagC on. gridy = 3;girdBag.setC on stra in ts(sysMessage,girdBagC on);dow nPan el.add(sysMessage);girdBagC on = new GridBagC on stra in ts();girdBagC on. gridx = 2;girdBagC on. gridy = 3;girdBag.setC on stra in ts(sysMessageButt on, gird

23、BagC on);dow nPan el.add(sysMessageButt on);girdBagC on = new GridBagC on stra in ts();girdBagC on. gridx = 0;girdBagC on. gridy = 4;girdBagC on. gridwidth = 3;girdBag.setC on stra in ts(showStatus,girdBagC on);dow nPan el.add(showStatus);conten tPa ne.add(messageScrollPa ne,BorderLayout.CENTER);con

24、 te ntPa ne.add(dow nPa nel,BorderLayout.SOUTH);/關(guān)閉程序時(shí)的操作this.addWi ndowListe ner(new Win dowAdapter()public void wi ndowClos in g(Wi ndowEve nt e) stopService();System.exit(O););/*事件處理*/public void actio nPeformed(Actio nEvent e) Object obj = e.getSource();if (obj = startServer | obj = startItem) /

25、 startService();else if (obj = stopServer | obj = stopItem) / int j=JOptio nPan e.showC on firmDialog(啟動(dòng)服務(wù)端停止服務(wù)端this,真的停止服務(wù)嗎?,停止服務(wù),JOptio nPan e.YES_OPTION,JOptio nPan e.QUESTION_MESSAGE);if (j = JOptio nPan e.YES_OPTION)stopService();else if (obj = portSet | obj = portItem) /調(diào)出端口設(shè)置的對(duì)話框PortCo nf por

26、tCo nf = new PortCo nf(this); portC on f.show();else if (obj = exitButt on | obj = exitItem) / int j=JOptio nPan e.showC on firmDialog(端口設(shè)置退出程序this,真的要退出嗎?,退出,JOptio nPan e.YES_OPTION,JOptio nPan e.QUESTION_MESSAGE);if (j = JOptio nPan e.YES_OPTION)stopService();System.exit(0);else if (obj = helpIte

27、m) /菜單欄中的幫助/調(diào)出幫助對(duì)話框Help helpDialog = new Help(this); helpDialog.show();發(fā)送系統(tǒng)消息else if (obj = sysMessage | obj = sysMessageButt on) / sen dSystemMessage();第12頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專用紙/*啟動(dòng)服務(wù)端第#頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專用紙*/ public void startService()try+port+端口偵聽.n);serverSocket = new ServerSocket(port,10); messageShow.appen

28、d(”服務(wù)端已經(jīng)啟動(dòng),在startServer.setE nabled(false);startItem.setE nabled(false);portSet.setE nabled(false);portItem.setE nabled(false);stopServer .setE nabled(true);stopItem .setE nabled(true); sysMessage.setE nabled(true);catch (Excepti on e)/System.out.pri ntl n( e);userL in kList = new UserL in kList();l

29、iste nThread = new ServerListe n( serverSocket,combobox, messageShow,showStatus,userL in kList);liste nThread.start();/*關(guān)閉服務(wù)端*/public void stopService()try/向所有人發(fā)送服務(wù)器關(guān)閉的消息se ndStopToAII();liste nThread.isStop = true;serverSocket.close();int count = userL in kList.getCo un t();int i =0;while( i coun t

30、)Node node = userL in kList.fi ndUser(i);no de.i nput .close();no de.output.close();no de.socket.close();i +;stopServer .setE nabled(false); stopItem .setE nabled(false); startServer.setE nabled(true); startItem.setE nabled(true);portSet.setE nabled(true);portItem.setE nabled(true);sysMessage.setE n

31、abled(false); messageShow.append(” 服務(wù)端已經(jīng)關(guān)閉 n); combobox.removeAllltems();combobox.addltem(” 所有人”);catch(Excepti on e)/System.out.pri ntl n( e);*向所有人發(fā)送服務(wù)器關(guān)閉的消息*/public void sen dStopToAII()int count = userL in kList.getCo un t();int i = 0;while(i coun t)Node node = userL in kList.fi ndUser(i);if(node

32、 = n ull) i +;con ti nue;trynode.output.writeObject(”服務(wù)關(guān)閉);no de.output.flush();catch (Excepti on e)/System.out.pri ntl n($+e);第14頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專用紙i+;/*第15頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專用紙向所有人發(fā)送消息*/用戶總數(shù)public void sen dMsgToAII(Stri ng msg)int count = userL in kList.getCo un t();/int i = 0;while(i coun t)Node node = us

33、erL in kList.fi ndUser(i); if(node = n ull) i +;con ti nue;系統(tǒng)信息”); tryno de.output.writeObject(”no de.output.flush();no de.output.writeObject(msg);no de.output.flush();catch (Excepti on e)/System.out.pri ntl n(+e); i+;sysMessage.setText();第#頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專用紙第#頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專用紙/*向客戶端用戶發(fā)送消息第#頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專

34、用紙*/public void sen dSystemMessage()String toSomebody = combobox.getSelectedltem().toStri ng();String message = sysMessage.getText() + n; messageShow.appe nd(message);/向所有人發(fā)送消息if(toSomebody.equalslgnoreCase(”所有人)sen dMsgToAll(message);else/向某個(gè)用戶發(fā)送消息Node node = userL in kList.fi ndUser(toSomebody);tr

35、ynode.output.writeObject(”系統(tǒng)信息”); no de.output.flush();no de.output.writeObject(message);no de.output.flush();catch(Excepti on e)/System.out.pri ntln (!+e);sysMessage.setText();將發(fā)送消息欄的消息清空public static void main(String args) ChatServer app = new ChatServer();(2) ServerListen.java:該類實(shí)現(xiàn)服務(wù)端用戶上線與下線的偵聽。該

36、類對(duì)用戶上線下線的偵聽是通過調(diào)用用戶鏈表類(UserLinkList )來(lái)實(shí)現(xiàn)的,當(dāng)用戶上線與下 線情況發(fā)生變化時(shí),該類會(huì)對(duì)主類的界面進(jìn)行相應(yīng)的修改。import java.awt.*;import java.awt.eve nt.*;import javax.swi ng.*;import javax.swi ng.eve nt.*;import java.io.*;import java .n et.*;/*服務(wù)端的偵聽類*/public class ServerListe n exte nds Thread ServerSocket server;JComboBox combobox;J

37、TextArea textarea;JTextField textfield;UserLi nkList userLi nkList;/用戶鏈表Node clie nt;ServerReceive recvThread;public boolea n isStop;/*聊天服務(wù)端的用戶上線于下線偵聽類*/public ServerListe n( ServerSocket server,JComboBox combobox,JTextArea textarea,JTextField textfield,UserL in kList userL in kList)this.server = se

38、rver;bobox = combobox;this.textarea = textarea;this.textfield = textfield;this.userL in kList = userL in kList;isStop = false;public void run()while(!isStop & !server.isClosed()tryclie nt = new Node();clie nt.socket = server.accept();clie nt.output=newObjectOutputStream(clie nt.socket.getOutputStrea

39、m();clie nt.output.flush();clie nt.i nput=newObjectI nputStream(clie nt.socket.getI nputStream();clie nt.user name = (Stri ng)clie nt. in put.readObject();/顯示提示信息combobox.addltem(clie nt.user name);userL in kList.addUser(clie nt);textarea.append(”用戶 ” + client.username + 上線 ” + n);textfield.setText(

40、”在線用戶 ” + userLinkList.getCount()+ 人n);recvThread = new ServerReceive(textarea,textfield,combobox,clie nt,userL in kList);recvThread.start();catch(Excepti on e)(3) ServerReceive.java:該類是實(shí)現(xiàn)服務(wù)器端的消息的收發(fā)的類。該類分別定 義了向某用戶及所有人發(fā)送消息的方法,發(fā)送的消息會(huì)顯示在主界面類的界面上。import javax.swi ng.*;import java.io.*;import java .n et.

41、*;/*服務(wù)器收發(fā)消息的類*/public class ServerReceive exte nds Thread JTextArea textarea;JTextField textfield;JComboBox combobox;Node clie nt;UserLi nkList userLi nkList;/用戶鏈表public boolea n isStop;public ServerReceive(JTextArea textarea,JTextField textfield, JComboBox combobox,Node clie nt,UserL in kList userL

42、 in kList) this.textarea = textarea;this.textfield = textfield;this.clie nt = clie nt;this.userL in kList = userL in kList;bobox = combobox;isStop = false;public void run()/向所有人發(fā)送用戶的列表sen dUserList();while(!isStop & !client.socket.isClosed()tryString type = (String)client.input.readObject(); if(type

43、.equalslgnoreCase(”聊天信息)String toSomebody = (String)client.input.readObject();String status = (String)client.input.readObject();String action = (String)client.input.readObject();String message = (String)client.input.readObject();String msg = clie nt.user name+ + actio n+ 對(duì)+ toSomebody+ 說(shuō):+ message +

44、 n;if(status.equalsIgnoreCase(悄悄話)msg =悄悄話+ msg;textarea.appe nd(msg);if(toSomebody.equalslgnoreCase(所有人)sen dToAll(msg);/向所有人發(fā)送消息elsetry聊天信息”);clie nt.output.writeObject(”clie nt.output.flush();clie nt.output.writeObject(msg);clie nt.output.flush();catch (Exceptio n e)/System.out.pri ntln (#+e);Nod

45、e node = userL in kList.fi ndUser(toSomebody);if(node != null)node.output.writeObject(”聊天信息”);no de.output.flush();no de.output.writeObject(msg);no de.output.flush();else if(type.equalslgnoreCase(”用戶下線)Node node = userL in kList.fi ndUser(clie nt.user name); userL in kList.delUser( no de);String msg

46、 = 用戶 ” + client.username + 下線 n;int count = userL in kList.getCo un t();combobox.removeAllltems();combobox.addltem(” 所有人”);int i = 0;while(i coun t)node = userL in kList.fi ndUser(i);if(node = nu II) i +;con ti nue;combobox.addItem (no de.user name);i+;combobox.setSelectedI ndex(O);textarea.appe nd

47、(msg);textfield.setText(”在線用戶+ userLinkList.getCount() + 第19頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專用紙n);第#頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專用紙sen dToAll(msg);/向所有人發(fā)送消息第20頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專用紙sendUserList();重新發(fā)送用戶列表,刷新break;catch (Exceptio n e) /System.out.pri ntl n( e);/*向所有人發(fā)送消息*/public void sen dToAII(Stri ng msg)int count = userL in kList.getCo un

48、t();int i = 0;while(i coun t)Node node = userL in kList.fi ndUser(i);if(node = nu II) i +;con ti nue;trynode.output.writeObject(”聊天信息”);no de.output.flush();no de.output.writeObject(msg);no de.output.flush();catch (Exceptio n e) /System.out.pri ntl n( e);i+;/*向所有人發(fā)送用戶的列表*/public void sen dUserList()

49、String userlist =;int count = userL in kList.getCo un t();int i = 0;while(i coun t)第21頁(yè)共18頁(yè)課程設(shè)計(jì)報(bào)告書專用紙Node node = userL in kList.fi ndUser(i);if(node = nu II) i +;con ti nue;userlist += no de.user name;userlist += n:i+;i = 0;while(i coun t)Node node = userL in kList.fi ndUser(i);if(node = nu II) i +;

50、con ti nue;trynode.output.writeObject(”用戶列表);no de.output.flush();no de.output.writeObject(userlist);no de.output.flush();catch (Exceptio n e)/System.out.pri ntl n( e);i+;(4) PortConf.java:該類繼承自JDialog,是用戶對(duì)服務(wù)器端偵聽端口進(jìn)行修改配置的類import java.awt.*;import javax.swi ng.border.*;import java .n et.*;import java

51、x.swi ng.*;import java.awt.eve nt.*;*生成端口設(shè)置對(duì)話框的類 */public class PortC onf exte nds JDialog JPa nel pan elPort = new JPa nel();JButt on save = new JButt on();JButt on cancel = new JButt on();public static JLabel DLGINFO=new JLabel(默認(rèn)端口號(hào)為:8888);JPa nel pan elSave = new JPa nel();JLabel message = new J

52、Label();public static JTextField portNumber ;public PortC on f(JFrame frame) super(frame, true);try jbI ni t();catch (Excepti on e) e.pri ntStackTrace();/設(shè)置運(yùn)行位置,使對(duì)話框居中Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocatio n( (int) (scree nSize.width - 400) / 2 + 50,(int) (screenSize.height - 600) / 2 + 150); this.setResizable(false);private void jblnit() throws Exception this.setSize(new Dimension(300, 120);this.setTitle( 端口設(shè)置);message.setText(” 請(qǐng)輸入偵聽的端口號(hào):); portNumber = new JTextField(10); portNumber.setText(+ChatServer.port);save.set

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(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)論