java网络聊天室课程设计报告(内附有代码)(编辑修改稿)内容摘要:

)。 (txtIP)。 (lblPort)。 (txtPort)。 (5, 5, 100, 400)。 (110, 5, 100, 30)。 (110, 35, 400, 370)。 (200, 410, 120, 30)。 (320, 410, 120, 30)。 (pnlServerInfo)。 (lblLog)。 (taLog)。 (btnStop)。 (btnSaveLog)。 // ===========在线用户面板 ==================== pnlUser = new JPanel()。 (null)。 lblMessage = new JLabel([用户消息 ])。 taMessage = new TextArea(20, 20)。 lblNotice = new JLabel(通知: )。 txtNotice = new JTextField(20)。 btnSend = new JButton(发送 (S))。 (true)。 (new ActionListener() { public void actionPerformed(ActionEvent arg0) { serverMessage()。 } })。 lblUserCount = new JLabel(在线总人数 0 人 )。 btnKick = new JButton(踢人 (K))。 (new ActionListener() { public void actionPerformed(ActionEvent arg0) { tiRen()。 } })。 lblUser = new JLabel([在线用户列表 ])。 lstUser = new JList()。 (17)。 (180)。 //指定的 固定单元格宽度值,而不是从列表元素计算而来的宽度值 (18)。 spUser = new JScrollPane()。 (R_ALWAYS)。 ().setView(lstUser)。 (5, 5, 100, 25)。 (5, 35, 300, 360)。 (310, 5, 100, 25)。 (310, 35, 220, 360)。 (5, 410, 40, 25)。 (50, 410, 160, 25)。 (210, 410, 80, 25)。 (320, 410, 100, 25)。 (440, 410, 80, 25)。 (lblMessage)。 (taMessage)。 (lblUser)。 (spUser)。 list = new JList()。 (new String[] { })。 (list)。 (lblNotice)。 (txtNotice)。 (btnSend)。 (lblUserCount)。 (btnKick)。 // ============主标签面板 ======================== tpServer = new JTabbedPane()。 (服务器管理 , pnlServer)。 (用户信息管理 , pnlUser)。 ().add(tpServer)。 setVisible(true)。 } protected void serverMessage() { // TODO 自动生成方法存根 = ()。 ()。 } protected void closeServer() { // TODO 自动生成方法存根 ()。 // } protected void saveLog() { // TODO 自动生成方法存根 try { FileOutputStream fileoutput = new FileOutputStream(, true)。 String temp = ()。 (())。 ()。 (null, 记录保存在 )。 } catch (Exception e) { (e)。 } } protected void tiRen() { // TODO 自动生成方法存根 ti = ().toString()。 log(Ti:+ti)。 } private void log(String string) { // TODO 自动生成方法存根 String newta = ()。 newta += (\n+string)。 (newta)。 } public void actionPerformed(ActionEvent evt) { } public static void main(String args[]) { new ServerFrame()。 } } public class Connection extends Thread { /** * 与客户端通讯 Socket */ private Socket Client。 /** * 在线用户列表 */ private VectorCustomer userOnline。 /** * 聊天信息 */ private VectorChat userChat。 /** * 从客 户到服务器 输入流 */ private ObjectInputStream fromClient。 /** * 传到客户端 打印流 */ private PrintStream toClient。 /** * 注册用户列表 */ private static Vector vList = new Vector()。 /** * 临时对象 */ private Object obj。 /** * 服务器日志窗体 */ private ServerFrame sFrame。 @SuppressWarnings(unchecked) /** * 创建与客户端通讯 */ public Connection(ServerFrame frame, Socket client, Vector u, Vector c) { Client = client。 userOnline = u。 userChat = c。 sFrame = frame。 try { // 发生双向通信 // 检索客户输入 fromClient = new ObjectInputStream(())。 // 服务器写到客户 toClient = new PrintStream(())。 } catch (IOException e) { try { ()。 } catch (IOException e1) { (不能建 立流 + e1)。 return。 } } ()。 } /** * 处理与客户端的通讯线程 */ public void run() { try {// obj是 Object类的对象 obj = (Object) ()。 if (().getName().equals(Customer)) { // serverLogin()。 serverLoginDB()。 } if (().getName().equals(Register_Customer)) { // serverRegiste()。 serverRegisteDB()。 } if (().getName().equals(Message)) { serverMessage()。 } if (().getName().equals(Chat)) { serverChat()。 } if (().getName().equals(Exit)) { serverExit()。 } } catch (IOException e) { (e)。 } catch (ClassNotFoundException e1) { (读对象发生错误。 + e1)。 } finally { try { ()。 } catch (IOException e) { (e)。 } } } /** * * 登录处理 */ @SuppressWarnings(deprecation) public void serve。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。