Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 13th, 2012  |  syntax: Java  |  size: 1.44 KB  |  views: 2  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package com.jesseweiman.RPChat.chat;
  2.  
  3. import com.jesseweiman.RPChat.gui.GUI;
  4. import com.jesseweiman.RPChat.Message;
  5. import com.jesseweiman.RPChat.Properties;
  6. import com.jesseweiman.RPChat.manager.ConfigManager;
  7. import com.jesseweiman.RPChat.manager.NetworkManager;
  8.  
  9. import java.util.concurrent.ConcurrentLinkedQueue;
  10.  
  11. /**
  12.  * Created with IntelliJ IDEA.
  13.  * User: Jesse
  14.  * Date: 10/2/12
  15.  * Time: 11:04 PM
  16.  * To change this template use File | Settings | File Templates.
  17.  */
  18. public class ChatManager {
  19.     public static final String DEFAULT_NAME = "Anonymous";
  20.  
  21.     GUI gui;
  22.     ConfigManager configManager;
  23.     NetworkManager networkManager;
  24.  
  25.     private ConcurrentLinkedQueue<Message> messages = new ConcurrentLinkedQueue<Message>();
  26.  
  27.     public ChatManager(GUI gui, ConfigManager configManager){
  28.         this.gui = gui;
  29.         this.configManager = configManager;
  30.         networkManager = new NetworkManager(this, configManager);
  31.     }
  32.  
  33.     public void sendMessage(String text){
  34.         configManager.load();
  35.         Message message = new Message(configManager.getString(Properties.NAME_KEY, DEFAULT_NAME), text);
  36.         messages.offer(message);
  37.         networkManager.sendMessage(message);
  38.     }
  39.  
  40.     public void receiveMessage(Message message){
  41.         messages.offer(message);
  42.         gui.updateChat();
  43.     }
  44.  
  45.     public Message[] getMessages() {
  46.         return messages.toArray(new Message[messages.size()]);
  47.     }
  48. }
clone this paste RAW Paste Data