Title:
*Description:
*Copyright:Copyright(c)2004
*Company:
*@authornotattributable*@version1.0*/publicclasschatFrameextendsJFrame{JPanelcontentPane;Labellabel1=newLabel();TextFieldtextField1=newTextField();Labellabel2=newLabel();TextFieldtextField2=newTextField();Buttonbutton1=newButton();TextAreatextArea1=newTextArea();DatagramPacketsendpacket,receivepacket;//定义发送和接受数据包DatagramSocketsendsocket,receivesocket;//定义发送和接受DatagramSocket//ConstructtheframepublicchatFrame(){enableEvents(AWTEvent.WINDOW_EVENT_MASK);try{jbInit();}catch(Exceptione){e.printStackTrace();}}//ComponentinitializationprivatevoidjbInit()throwsException{//定义个组件和他们的布局contentPane=(JPanel)this.getContentPane();label2.setAlignment(Label.CENTER);label2.setFont(newjava.awt.Font("SansSerif",0,15));label2.setForeground(Color.black);label2.setText("消息编辑框");label1.setBounds(newRectangle(14,17,133,32));contentPane.setLayout(null);this.setSize(newDimension(500,400));this.setTitle("用UDP实现聊天");textField1.setBackground(SystemColor.text);textField1.setColumns(0);textField1.setFont(newjava.awt.Font("Dialog",0,16));textField1.setText("");textField1.setBounds(newRectangle(129,72,200,61));label1.setAlignment(Label.CENTER);label1.setFont(newjava.awt.Font("Dialog",0,15));label1.setText("输入对方IP地址");label2.setBounds(newRectangle(23,86,108,28));try{sendsocket=newDatagramSocket(5000);//初始化receivesocket=newDatagramSocket(5001);}catch(SocketExceptionse){//可能产生Socketexception类的异常se.printStackTrace();System.exit(0);}button1.setBackground(Color.magenta);button1.setFont(newjava.awt.Font("Dialog",0,13));button1.setLabel("发送消息");button1.setBounds(newRectangle(374,23,88,42));button1.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(ActionEvente){button1_actionPerformed(e);}});textField2.setBackground(SystemColor.activeCaptionBorder);textField2.setFont(newjava.awt.Font("Dialog",1,18));textField2.setLocale(java.util.Locale.getDefault());textField2.setText("");textField2.setBounds(newRectangle(166,21,169,29));textArea1.setFont(newjava.awt.Font("Dialog",0,13));textArea1.setText("");textArea1.setBounds(newRectangle(46,157,382,185));contentPane.setBackground(newColor(113,111,159));jButton1.setBackground(Color.pink);jButton1.setBounds(newRectangle(374,86,87,42));jButton1.setFont(newjava.awt.Font("Dialog",0,13));jButton1.setText("刷新频道");jButton1.addActionListener(newjava.awt.event.ActionListener(){publicvoidactionPerformed(ActionEvente){jButton1_acti...1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。
碎片内容